对于shell里面的set以及eval的用法:
set的作用设置位置参数(同命令行脚本的传参)
eval的作用是进行第二次描述
root@ubuntu:/home/xpg#set--helloshanghailiangge root@ubuntu:/home/xpg#evalecho\$$# liangge root@ubuntu:/home/xpg#
shell里面的关于 "$"的作用:
$0:脚本名称
如果想获得脚本的路径以及脚本的名称可以使用dirname和basename
@H_502_15@root@ubuntu:/home/xpg#dirname/home/xpg/1.sh /home/xpg root@ubuntu:/home/xpg#basename/home/xpg/1.sh 1.sh$n:输出具体的参数
$#:总几个参数
$*:和下面的$@在不带引号的情况下是一样的
$@:带上引号的区别。可以用set设置位置参数看看,这两个一般不用
$?:对上一个命令执行的判断,如果正确,为0,否则为非零
企业中使用$?的用法:
判断脚本命令,脚本是否执行成功
*若在脚本中,使用exit n来返回数字给$?
*若在函数中,使用return来返回数字给$?
$$:获得脚本的进程号
生产的上的例子就是多次执行一个脚本的时候,第一次没有执行完,第二次就要先将这个脚本的pid删除,在使用$$判断这个脚本的pid
bash shell的内置命令:
echo:
-e:解析转义字符(下面用到)
\n:换行
\r:回车
\t:tab健
\b:退格
@H_502_15@root@ubuntu:/home/xpg#echome;echoyou me you root@ubuntu:/home/xpg#echo-nme;echoyou meyou root@ubuntu:/home/xpg#printf"log\tlog\npog\tpog\n" loglog pogpog root@ubuntu:/home/xpg#echo-e"log\tlog\npog\tpog" loglog pogpog root@ubuntu:/home/xpg#echo-elog\tlog\npog\tpog logtlognpogtpogexec:执行完命令会退出当前的shell的
${parameter:-word}:如果变量值为空,则返回的是word字符
@H_502_15@root@ubuntu:/home/xpg#echo$test root@ubuntu:/home/xpg#echo${test:-word} word root@ubuntu:/home/xpg#echo${test:=word} word root@ubuntu:/home/xpg#echo$test word root@ubuntu:/home/xpg#${parameter:=word}:和上面的一样,但是会将word的值赋给变量
${parameter:?word}:如果parameter变量值为空或者未赋值,那么word字符串被作为标准错误输出
${parameter:+word}:如果parameter的值为空,则什么也不做,否则word的值将代替变量
@H_502_15@root@ubuntu:/home/xpg#echo$test root@ubuntu:/home/xpg#echo${test:?nodefined} bash:test:nodefined root@ubuntu:/home/xpg#echo${test:+gg} root@ubuntu:/home/xpg#test=rr root@ubuntu:/home/xpg#echo${test:+gg} gg root@ubuntu:/home/xpg#