Linux-shell初学(一)

  今天看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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值