2. 如果#!之后的解释程序是一个可执行文件,那么执行这个脚本时,它就会把文件名及其参数一起作为参数传给那个解释程序去执行。
3. 如果#!指定的解释程序没有可执行权限,则会报错“bad interpreter: Permission denied”。
如果#!指定的解释程序不是一个可执行文件,那么指定的解释程序会被忽略,转而交给当前的SHELL去执行这个脚本。
4. 如果#!指定的解释程序不存在,那么会报错“bad interpreter: No such file or directory”。
注意:#!之后的解释程序,需要写其绝对路径(如:#!/bin/bash),它是不会自动到$PATH中寻找解释器的。
5. 当然,如果你使用”bash test.sh”这样的命令来执行脚本,那么#!这一行将会被忽略掉,解释器当然是用命令行中显式指定的bash。
http://smilejay.com/2012/03/linux_shebang/
#set -x
set +e
set 设置脚本执行方式
-x 执行指令后,会先显示该指令及所下的参数。
+ 取消某个set曾启动的参数。
-e 若指令传回值不等于0,则立即退出shell。 ###############################################################################
# Check CPU core number
###############################################################################
###############################################################################
# Set envionment variables
###############################################################################
source ~/.bashrc
设置环境变量
if [ ! -d "*" ];then
…… ……
-d 文件夹是否存在, 存在为真
if [ ! -L "*.so" ];then
-L 符号链接是否存在,存在为真
###############################################################################
# Set build.sh input parameters struct
###############################################################################
TEMP=`getopt -o c:h::m:v:: -n 'build.sh' -- "$@"`
getopt 取输入参数
-o :-o, --options shortopts 设置短参数
Each short option character in shortopts may be followed by one colon to indicate
it has a required argument, and by two colons to indicate it has an optional argument(可选参数).
后面一个冒号是必选参数, 即-参数后面必须有选项;后面两个冒号可选参数
-n :出错时报告错误文件的名字
-- : 后接参数
$@所有参数
if [ $? != 0 ] ; then echo "Terminating..." >&2 ;echo "-h help";exit 1 ; fi
eval set -- "$TEMP"
eval set: Without options, the name and value of each shell variable are displayed in a format that can be
reused as input for setting or resetting the currently-set variables. Read-only variables cannot
be reset. In posix mode, only shell variables are listed. The output is sorted according to the
current locale. When options are specified, they set or unset shell attributes. Any arguments
remaining after option processing are treated as values for the positional parameters and are
assigned, in order, to $1, $2, ... $n.
shell 参数重新排列, 排列规则 "$TEMP", 我的解释.
VERSION=0.1.0
while true ; do
case "$1" in
-c|--c-long)
参数-c
case "$2" in
"all") make_all clean ;shift 2 ;;
shift 2的作用 参数向前移两个, sh build.sh -c all 变为 sh build.sh 从而退出while
参数 -c all
... ...
... ...
esac
esac
done
echo "Remaining arguments:"
for arg do
echo '--> '"\`$arg'" ;
done