调用时是否完整读取shell脚本? [英] Are shell scripts read in their entirety when invoked?

查看:69
本文介绍了调用时是否完整读取shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问,因为我最近更改了正在执行的KornShell(ksh)脚本.保存更改后不久,执行过程失败.从错误消息来看,似乎正在运行的进程已经看到了我的某些(但不是全部)更改.强烈建议在调用Shell脚本时,不会将整个脚本读入内存.

I ask because I recently made a change to a KornShell (ksh) script that was executing. A short while after I saved my changes, the executing process failed. Judging from the error message, it looked as though the running process had seen some -- but not all -- of my changes. This strongly suggests that when a shell script is invoked, the entire script is not read into memory.

如果此结论正确,则表明应该避免对正在运行的脚本进行更改.

If this conclusion is correct, it suggests that one should avoid making changes to scripts that are running.

$ uname -a
SunOS blahblah 5.9 Generic_122300-61 sun4u sparc SUNW,Sun-Fire-15000

推荐答案

否. Shell脚本按行或按命令读取,后跟;,但诸如if ... fi块之类的块除外,这些块被解释为大块:

No. Shell scripts are read either line-by-line, or command-by-command followed by ;s, with the exception of blocks such as if ... fi blocks which are interpreted as a chunk:

Shell脚本是一个包含Shell命令的文本文件.当这样 调用Bash时,文件用作第一个非选项参数,并且 -b和-s选项均未提供(请参阅调用Bash"),Bash 从文件读取并执行命令,然后退出.这种模式 操作将创建一个非交互式外壳.

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块的fi执行命令.

You can demonstrate that the shell waits for the fi of an if block to execute commands by typing them manually on the command line.

http://www.gnu.org/software/bash/manual/bashref.html#Executing-Commands

http://www.gnu.org/software/bash/manual/bashref.html#Shell-Scripts

这篇关于调用时是否完整读取shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆