select fruit in pear apple banana others quit
do
if [ ! -z "$fruit" ] ; then
[ "$fruit" == "quit" ] && exit 0 || echo "you choosed $REPLY and you like $fruit"
else
echo "wrong argv $REPLY"
fi
done
#restore $PS3
PS3=$oPS3
执行结果
1
2
3
4
5
6
7
8
9
10
11
[iyunv@www shell]# ./select.sh
1) pear
2) apple
3) banana
4) others
5) quit
请选择喜欢的水果q退出:1
you choosed 1 and you like pear
请选择喜欢的水果q退出:6
wrong argv 6
请选择喜欢的水果q退出:5
#!/bin/bash
#save PS3
oPS3=$PS3
PS3="choose the way:"
function way1 (){
echo "you are using () to add"
tmp1=$((nu1 + nu2))
echo "value is $tmp1"
}
function way2(){
echo "you are using expr to add"
echo "value is `expr ${nu1} + ${nu2}`"
}
function way3(){
echo "you are using let to add"
let tmp2=${nu1}+${nu2}
echo "value is $tmp2"
}
read -p "please input two to test:" nu1 nu2
select cal in '(())' 'expr' 'let' 'q'
do
case $cal in
'(())')
way1;;
'expr')
way2;;
'let')
way3;;
'q')
exit 0;;
* )
echo "wrong argv";;
esac
done
#restore PS3
PS3=$oPS3
执行结果为
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[iyunv@www shell]# ./select2.sh
please input two to test:2 3
1) (())
2) expr
3) let
4) q
choose the way:3
you are using let to add
value is 5
choose the way:1
you are using () to add
value is 5
choose the way:2
you are using expr to add
value is 5
choose the way:4
和本次无关
突然想写这样一个脚本
对每一个非系统用户说声hello,用户名,i know you are form 用户组名
我的思路就是shell不能是/sbin/nologin,家目录不能为/sbin我的文件时这样子的
好吧,我承认这个更蹩脚,改天看下详细的awk命令
1
2
3
4
5
#!/bin/bash
#change ps2
tmp=`cat /etc/passwd`
cat /etc/passwd 2>/dev/null|grep -v /sbin/nologin|grep -v /sbin|awk -F ":" '{print "hello,"$1",i know you are from "$5"."}'
执行结果为:
1
2
3
[iyunv@www shell]# ./while.sh
hello,root,i know you are from root.
hello,liuliancao,i know you are from liuliancao.