今天看shell编程,顺手发到博客吧
#!/bin/sh
# first
# this file looks through all the files in the current dirctory for the string posix, and then prints the names of those files to
# the standard output.
for file in *
do
if grep -q POSIX $file
then
echo $file
fi
done
exit 0
#!/bin/sh
var="hello world"
echo $var
echo "the program $0 is now running"
echo "the second parameter was $2"
echo "the first paramater was $1"
echo "the parameter list was $*"
echo "the user's home directory is $HOME"
echo "please enter a new greeting"
read var
echo "the script is now complete"
exit 0
#!/bin/sh
var1="hello"
var2="heelo"
if [ $var1 != $var2 ]
then
echo "var1 not equal var2"
fi
var2="hello"
if [ $var1 = $var2 ]
then
echo "var1 equal var2"
else
echo "var1 not equal var2"
fi
exp1=2
exp2=2
if [ $exp1 -eq $exp2 ]
then
echo "exp1 equal exp2"
elif [ $exp1 -eq 2]
then
echo "exp1 equal 2"
else
echo "exp1 not equal exp2"
fi
exit 0
#!/bin/sh
myvar="hi there"
echo $myvar
echo "$myvar"
echo '$myvar'
echo \$myvar
echo Enter some text
read myvar
echo '$myvar' now equals $myvar
exit 0
#!/bin/sh
for var in a b c d e f
do
printf "%s " $var
#bu huan hang
printf "\n"
done
exit 0
#!/bin/sh
echo "enter a command to simulation the terminal"
read cmd
while [ "$cmd" != exit ]
do
$cmd
read cmd
done
exit 0
#!/bin/sh
read var
case $var in
1) printf "%d " $var;;
2) echo 2;;
3) echo 3;;
esac
exit 0