我是新来的bash,并试图了解下面的脚本正在做什么,我知道-e
是退出,但我不知道什么-se
或$delimiter
是什么?bash -s做什么?
$delimiter = 'EOF-MY-APP';
$process = new SSH(
"ssh $target 'bash -se' << \\$delimiter".PHP_EOL
.'set -e'.PHP_EOL
.$command.PHP_EOL
.$delimiter
);
我是新来的bash,并试图了解下面的脚本正在做什么,我知道-e
是退出,但我不知道什么-se
或$delimiter
是什么?bash -s做什么?
$delimiter = 'EOF-MY-APP';
$process = new SSH(
"ssh $target 'bash -se' << \\$delimiter".PHP_EOL
.'set -e'.PHP_EOL
.$command.PHP_EOL
.$delimiter
);
从man bash
:
-s If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell.
从help set
:
-e Exit immediately if a command exits with a non-zero status.
所以,这是告诉bash读了剧本从Standa执行rd输入,如果脚本中的任何命令(来自stdin)失败,立即退出。
分隔符用于标记脚本的开始和结束。这被称为Here Document或heredoc。
'-s'从标准输入中读取命令。 http://linux.die.net/man/1/bash(来源:十秒谷歌搜索) –
^^那么,'-s'是多余的?任何人都可以提供一个例子,其中'-s'是必需的吗? – anishsane
Stack Overflow是编程和开发问题的网站。这个问题似乎与题目无关,因为它不涉及编程或开发。请参阅帮助中心的[我可以询问哪些主题](http://stackoverflow.com/help/on-topic)。也许[超级用户](http://superuser.com/)或[Unix&Linux堆栈交换](http://unix.stackexchange.com/)会是一个更好的地方。 – jww