我问是因为我最近对正在执行的 KornShell (ksh) 脚本进行了更改。保存更改后不久,执行过程失败。从错误消息来看,正在运行的进程似乎看到了我的一些——但不是全部——我的更改。这强烈表明当调用 shell 脚本时,不会将整个脚本读入内存。
如果这个结论是正确的,则表明应该避免对正在运行的脚本进行更改。
$ uname -a
SunOS blahblah 5.9 Generic_122300-61 sun4u sparc SUNW,Sun-Fire-15000
最佳答案
没有。 Shell 脚本可以逐行读取,也可以逐个命令读取,后跟 ;
,但 if ... fi
block 除外被解释为一个 block :
A shell script is a text file containing shell commands. When such a file is used as the first non-option argument when invoking Bash, and neither the -c nor -s option is supplied (see Invoking Bash), Bash reads and executes commands from the file, then exits. This mode of operation creates a non-interactive shell.
您可以通过在命令行中手动键入命令来演示 shell 等待 if
block 的 fi
来执行命令。
http://www.gnu.org/software/bash/manual/bashref.html#Executing-Commands
http://www.gnu.org/software/bash/manual/bashref.html#Shell-Scripts
关于shell - 调用时是否完整读取 shell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18034527/