特殊运算符 - 在 bash
Special operator - in bash
我注意到 crontab 的用法
crontab -
如果我在这个命令中回显一些内容,它能够覆盖 cron 内容,例如,
$ crontab -l
...
# m h dom mon dow command
* * * * * /bin/ls
$ crontab -l | sed 's/ls/cd/g' | crontab -
$ crontab -l
...
# m h dom mon dow command
* * * * * /bin/cd
问题:
bash 中的“-”是什么意思? bash 中的“-”是通用的吗?
来自 crontab 联机帮助页 man crontab
:
The first form of this command is used to install a new crontab from
some named file or standard input if
the pseudo-filename "-" is given.
因此 -
被标准输入(您通过管道传输给它的内容)取代。
-
并不特定于 bash。这是许多 unix 程序作为文件使用的约定,表示 "stdin"(输入)或 "stdout"(输出)。
在这种情况下,crontab
通常采用一个参数,该参数是要作为新的 cron 内容读取和加载的文件名。相反,传递 -
意味着 "take the content from standard input".
我注意到 crontab 的用法
crontab -
如果我在这个命令中回显一些内容,它能够覆盖 cron 内容,例如,
$ crontab -l
...
# m h dom mon dow command
* * * * * /bin/ls
$ crontab -l | sed 's/ls/cd/g' | crontab -
$ crontab -l
...
# m h dom mon dow command
* * * * * /bin/cd
问题: bash 中的“-”是什么意思? bash 中的“-”是通用的吗?
来自 crontab 联机帮助页 man crontab
:
The first form of this command is used to install a new crontab from some named file or standard input if the pseudo-filename "-" is given.
因此 -
被标准输入(您通过管道传输给它的内容)取代。
-
并不特定于 bash。这是许多 unix 程序作为文件使用的约定,表示 "stdin"(输入)或 "stdout"(输出)。
在这种情况下,crontab
通常采用一个参数,该参数是要作为新的 cron 内容读取和加载的文件名。相反,传递 -
意味着 "take the content from standard input".