例如,
elif [[ $append = $1 ]]
then
touch ~/directory/"$2".txt
echo "$variable_in_question" >> ~/directory/"$2".txt
Run Code Online (Sandbox Code Playgroud)
要创建一个包含所有后续输入的文本文件"$2",或者附加一个包含所有后续输入的现有文本文件"$2",我将使用什么来代替"$variable_in_question"第 4 行?
我基本上想要"$*",但省略了"$1"和"$2"。
我在:GNU bash,版本 4.4.12(1)-release (x86_64-pc-linux-gnu)
脚本是:(note.sh)
#! /bin/bash
edit="edit"
if [[ $edit = $1 ]]
then
touch ~/.notes/"$2".txt
$EDITOR ~/.notes/"$2".txt
else
tree ~/.notes
fi
Run Code Online (Sandbox Code Playgroud)
我希望如果我在 bash 中输入:
./note.sh
我得到的输出就像我输入的一样
tree ~/.notes
但我希望这个脚本基本上接受参数,所以如果我输入
./note.sh edit new_note
然后如果 new_note.txt 不存在,
touch ~/.notes/new_note.txt
那么(Gedit 对我来说)文本编辑器打开 new_note .txt 在终端中进行编辑
else 语句有效,但
./note.sh edit new_note返回
./note.sh: line 10: /home/username/.notes/testnote.txt: Permission denied
它可以触摸但不是编辑器。这里被拒绝许可是什么意思?
提前致谢!我对 shell 脚本和 askubuntu 都很陌生,非常感谢任何帮助