shell - 调用时是否完整读取 shell 脚本?

标签 shell unix scripting solaris ksh

我问是因为我最近对正在执行的 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/

相关文章:

unix - 高级 grep Unix

c - 进程之间共享线程?

linux - 如何计算 ps 命令输出 bash 脚本中 rss 和 vsz 之间的关系?

postgresql - 使用 shell 脚本在 postgresql 中插入列时出错?

mysql - 如何通过shell命令删除mysql数据库

linux - 带有使文件可执行的参数的 Bash 脚本

linux - unix中同一目录中的多个文件比较

c - 什么程序/实用程序在源代码中使用特殊字符串 "@(#)"?

java - 在Jmeter中使用Java参数化XML标签

javascript - 用于丢失文本样式的脚注的 Indesign 脚本