shell script
-
Shebang
#! /bin/bash #! /bin/python
-
执行方式
# 在当前进程执行, 所赋值的变量会保留 source test.sh . test.sh # 在子进程中执行, 脚本执行结束子进程退出, 所赋值的变量会被回收 bash test.sh ./test.sh
-
字符串内执行命令用 ``
root@ubuntu:~/test# cat test.sh #! /bin/bash echo "Current time: `date`"; root@ubuntu:~/test# bash test.sh Current time: Wed 24 Aug 2022 05:58:00 PM CST
-
print user info
echo "User name is: $USER"; echo "User uid is: $UID"; echo "User home is: $HOME";
-
print who login
who
-
特殊符号
#取出当前变量的值 ${vars} $vars # 在括号``中执行命令, 且得到执行结果 $(cmd) `cmd` # 开启子shell执行命令 (pwd; ls; type;)