1
2
3
|
if
ls sam* &> /dev/
null
; then
echo
"Hi,it's here."
fi
|
1
2
3
|
if
grep
"^hive"
/etc/passwd; then
grep
"^hive"
/etc/passwd | cut -d: -f1,
3
,
7
fi
|
1
2
3
4
5
6
7
8
9
|
#!/bin/bash
#
A=$RANDOM
B=$RANDOM
if
[ $A -ge $B ]; then
echo
"Max number is $A."
else
echo
"Max number is $B."
fi
|
1
2
3
4
5
6
7
8
|
#!/bin/bash
#
A=$RANDOM
if
[ $[$A%
2
] -eq
0
]; then
echo
"$A: Even"
else
echo
"$A: Odd"
fi
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#!/bin/bash
#
Shell=`grep
"^$1:"
/etc/passwd | cut -d: -f7`
if
[ -z $Shell ]; then
echo
"No such user or User's shell is null."
exit
10
fi
if
[
"$Shell"
==
"/bin/bash"
]; then
echo
"Bash User."
Ret=
0
else
echo
"Not Bash User."
Ret=
9
fi
exit $Ret
|
1
2
3
4
5
6
7
|
#!/bin/bash
#
if
[[ $
1
=~ [Mm]emory$ ]]; then
free -m
else
cat /proc/uptime
fi
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/bin/bash
#
SvcName=`basename $
0
`
LockFile=
"/var/lock/subsys/$SvcName"
if
[ $# -lt
1
]; then
echo
"Usage: $SvcName {start|stop|restart|status}"
exit
3
fi
if
[ $
1
==
'start'
]; then
if
[ -e $LockFile ]; then
echo
"$SvcName is running."
else
touch $LockFile &> /dev/
null
echo
"Starting $SvcName successfully."
fi
elif [ $
1
==
'stop'
]; then
if
[ -e $LockFile ];then
rm -f $LockFile &> /dev/
null
echo
"Stopping $SvcName finished."
else
echo
"$SvcName is stopped yet."
fi
elif [ $
1
==
'restart'
]; then
rm -f $LockFile &> /dev/
null
touch $LockFile &> /dev/
null
echo
"Restarting $SvcName successfully."
elif [ $
1
==
'status'
]; then
if
[ -e $LockFile ]; then
echo
"$SvcName is running."
else
echo
"$SvcName is stopped."
fi
else
echo
"Usage: $SvcName {start|stop|restart|status}"
exit
4
fi
|
1
2
3
4
5
6
7
|
#!/bin/bash
read -p
"please input a number: "
num
if
[ $num -gt
1
-a $num -lt
100
];then
echo
"available"
else
echo
"invalid input"
fi
|
1
|
[ -d /tmp/test ] || mkdir /tmp/test && echo
"directory exists"
|