小编Ore*_*asm的帖子

如何在 bash 脚本中省略某些输入变量(如 $1 和 $2)时使用 $*?

例如,

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"

command-line bash scripts

15
推荐指数
3
解决办法
2897
查看次数

为什么 bash 拒绝我的 shell 脚本使用默认文本编辑器打开文本文件的权限?

我在: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 都很陌生,非常感谢任何帮助

permissions command-line bash scripts

5
推荐指数
2
解决办法
1250
查看次数

标签 统计

bash ×2

command-line ×2

scripts ×2

permissions ×1