sh/bash/dash/ksh/zsh等Shell脚本
-
astolia
- 论坛版主
- 帖子: 6703
- 注册时间: 2008-09-18 13:11
#16
帖子
由 astolia » 2014-10-11 19:24
ubuntu上,如果不去改sh的链接对象,sh xxx就等同于dash xxx也就是用dash来执行脚本。#!这行只有直接用文件名运行时才有效
你想写通用点,就只用=来比较
a shell builtin就是shell的内建命令。要查shell的manpage。
source的通用程度也不高,dash就不认。最好还是用 . 替代
man bash中可以查到
代码: 全选
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell
environment and return the exit status of the last command exe‐
cuted from filename. If filename does not contain a slash,
filenames in PATH are used to find the directory containing
filename. The file searched for in PATH need not be executable.
When bash is not in posix mode, the current directory is
searched if no file is found in PATH. If the sourcepath option
to the shopt builtin command is turned off, the PATH is not
searched. If any arguments are supplied, they become the posi‐
tional parameters when filename is executed. Otherwise the
positional parameters are unchanged. The return status is the
status of the last command exited within the script (0 if no
commands are executed), and false if filename is not found or
cannot be read.
第一句就说明是在当前shell环境下执行,也就是相当于你直接在shell中输入脚本中的所有内容。你脚本不管输入什么最后都会执行exit语句,在shell中执行exit当然就会退出了
-
super_art
- 帖子: 9
- 注册时间: 2014-10-09 16:23
- 系统: win8.1 pro
#17
帖子
由 super_art » 2014-10-14 9:50
astolia 写了:ubuntu上,如果不去改sh的链接对象,sh xxx就等同于dash xxx也就是用dash来执行脚本。#!这行只有直接用文件名运行时才有效
你想写通用点,就只用=来比较
a shell builtin就是shell的内建命令。要查shell的manpage。
source的通用程度也不高,dash就不认。最好还是用 . 替代
man bash中可以查到
代码: 全选
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell
environment and return the exit status of the last command exe‐
cuted from filename. If filename does not contain a slash,
filenames in PATH are used to find the directory containing
filename. The file searched for in PATH need not be executable.
When bash is not in posix mode, the current directory is
searched if no file is found in PATH. If the sourcepath option
to the shopt builtin command is turned off, the PATH is not
searched. If any arguments are supplied, they become the posi‐
tional parameters when filename is executed. Otherwise the
positional parameters are unchanged. The return status is the
status of the last command exited within the script (0 if no
commands are executed), and false if filename is not found or
cannot be read.
第一句就说明是在当前shell环境下执行,也就是相当于你直接在shell中输入脚本中的所有内容。你脚本不管输入什么最后都会执行exit语句,在shell中执行exit当然就会退出了
谢谢!