1.一些SHELL命令:
$ls -l > lsoput.txt #覆盖
$ps >> lsoput.txt #附加
$kill -HUP 1234 >killouterr.txt 2>&1
$ps -xo comm | sort | uniq | grep -v sh | more
2 $ss=hello $ss="hello" $ss=7+5
$echo $ss $echo $ss $echo $ss
result: hello result: hello result:7+5
$read ss $echo $ss
wie get $echo "$ss"
$echo $ss $echo '$ss'
wie get $echo /$ss
3. 环境变量
$HOME $PATH $PS1 $PS2 $IFS $0 $# $$
参数变量
$0 $1 $2 .... $* $@
4. 条件测试,可进行字符串比较,算术比较,文件测试
test 或 [ ]
5. if condition if condition
then then
statements statements
else elif condition; then
statements statements
fi else
statements
fi
6. for file in $(ls f*.sh)
do
lpr $file
done
7. #!/bin/sh
foo=1
while [ "$foo" le 20 ]
do
fo=$($(foo+1))
done
8.until condtion
do
statements
done
9.#i/bin/sh
read timeofday
case "$timeofday" in
yes | y | Yes |YES )
echo "Good"
echo "darly"
;;
[nN]*)
echo "good"
;;
*)
exit 1
;;
esac
10. && || {}
11.SHELL程序中,当一个函数被调用,脚本程序大位置参数$* $# $1等会被替换为函数大参数,函数执行完后,这些参数会恢复原直,让函数返回变量的作法通常是在函数中对变量复直,然后在main函数中调用该变量,可以用local声明局部变量。
#!/bin/sh
yes_or_no()
{
echo "your name is $* $0 $1 $2 $3"
while :
do
echo -n "Enter yes or no: "
read x
case "$x" in
[yY]*) return 0;;
[nN]*) return 1;;
*) echo "Enter yes or no"
esac
done
}
12
echo "parameters are $@"
if yes_or_no "haha dede yeye"
#if :
then
echo "Hi $1"
else
echo "Never mind"
fi
exit 0
12.break : continue . eval $(()) exec eixt n export expr printf return set shift trap unset
13 find grep
14.算术扩展$((..))与执行命令$(..)的区别,参数扩展${param},here文档<<
15.脚本调试 sh -n -x -v
$ls -l > lsoput.txt #覆盖
$ps >> lsoput.txt #附加
$kill -HUP 1234 >killouterr.txt 2>&1
$ps -xo comm | sort | uniq | grep -v sh | more
2 $ss=hello $ss="hello" $ss=7+5
$echo $ss $echo $ss $echo $ss
result: hello result: hello result:7+5
$read ss $echo $ss
wie get $echo "$ss"
$echo $ss $echo '$ss'
wie get $echo /$ss
3. 环境变量
$HOME $PATH $PS1 $PS2 $IFS $0 $# $$
参数变量
$0 $1 $2 .... $* $@
4. 条件测试,可进行字符串比较,算术比较,文件测试
test 或 [ ]
5. if condition if condition
then then
statements statements
else elif condition; then
statements statements
fi else
statements
fi
6. for file in $(ls f*.sh)
do
lpr $file
done
7. #!/bin/sh
foo=1
while [ "$foo" le 20 ]
do
fo=$($(foo+1))
done
8.until condtion
do
statements
done
9.#i/bin/sh
read timeofday
case "$timeofday" in
yes | y | Yes |YES )
echo "Good"
echo "darly"
;;
[nN]*)
echo "good"
;;
*)
exit 1
;;
esac
10. && || {}
11.SHELL程序中,当一个函数被调用,脚本程序大位置参数$* $# $1等会被替换为函数大参数,函数执行完后,这些参数会恢复原直,让函数返回变量的作法通常是在函数中对变量复直,然后在main函数中调用该变量,可以用local声明局部变量。
#!/bin/sh
yes_or_no()
{
echo "your name is $* $0 $1 $2 $3"
while :
do
echo -n "Enter yes or no: "
read x
case "$x" in
[yY]*) return 0;;
[nN]*) return 1;;
*) echo "Enter yes or no"
esac
done
}
12
echo "parameters are $@"
if yes_or_no "haha dede yeye"
#if :
then
echo "Hi $1"
else
echo "Never mind"
fi
exit 0
12.break : continue . eval $(()) exec eixt n export expr printf return set shift trap unset
13 find grep
14.算术扩展$((..))与执行命令$(..)的区别,参数扩展${param},here文档<<
15.脚本调试 sh -n -x -v