<分区>
这里是新手 shell 脚本编写者。
我在 bash shell 中。我自己运行以下脚本是可行的,但当我使用 sudo 时却不行。您可能会说,touch
错误只是为了确保将某些内容写入日志文件。
dave@pi1:~ $ ./test.sh
touch: cannot touch '/asdf/asdf/asdf': No such file or directory <--- As expected
dave@pi1:~ $ sudo ./test.sh
./test.sh: 2: ./test.sh: Syntax error: redirection unexpected <--- why this not work?
dave@pi1:~ $
脚本...
LOG_FILE=/var/log/usbhook
exec > >(tee -a ${LOG_FILE} )
exec 2> >(tee -a ${LOG_FILE} >&2)
touch /asdf/asdf/asdf
目的是在我插入 USB 内存棒时触发脚本,因此我假设它在使用 sudo 运行时应该可以工作。
编辑
这与评论中链接的其他问题不同。这与不能在 shell 中使用的运算符有关。