[toc]
1 $@
$@所有參數(shù)列表。如"$@"用「"」括起來的情況、以"$1" "$2" … "$n"的形式輸出所有參數(shù)。
$0: Shell本身的文件名
$? :最后運(yùn)行的命令的結(jié)束代碼(返回值)
${parameter:-word}
# If parameter is unset or null, the expansion of word is substituted.
# Otherwise, the value of parameter is substituted.
參考:
http://www.cnblogs.com/fhefh/archive/2011/04/15/2017613.html
2 case
case $number in
1|2|3)
echo "the number you input is 1~3"
;;
4|5|6|7|8|9|10)
echo "the number you input is 4~10"
;;
*)
echo "error! the number you input isn't 1 to 10"
;;
esac
參考:
http://yangdong.blog.51cto.com/2959198/545931
3 if
if 條件
then
Command
else
Command
fi
# -z STRING: the length of STRING is zero,如果后面的string為空
if [ -z "${SPARK_HOME}" ]; then
source "$(dirname "$0")"/find-spark-home
fi
# if [ -f file ] 如果文件存在
# if [ -d ... ] 如果目錄存在
# if [ -n $string ] 如果string 非空(非0),返回1(true)
參考:
http://www.cnblogs.com/myitm/archive/2012/07/05/2577416.html
http://wiki.jikexueyuan.com/project/linux-command/chap28.html
4 source
和.的效果一樣
source FileName
作用:在當(dāng)前bash環(huán)境下讀取并執(zhí)行FileName中的命令。
5 set
declare mylove='Visual C++' #定義新環(huán)境變量
set -a mylove #設(shè)置為環(huán)境變量
env | grep mylove #顯示環(huán)境變量值
-a:標(biāo)示已修改的變量,以供輸出至環(huán)境變量。
參考:
http://man.linuxde.net/set
6 << 重定向
重定向
# cmd << delimiter
cat << EOF > output.sh
echo "hello"
echo "world"
EOF