shell 学习 demo1

根据Linux命令行与shell脚本编程大全 练习测试的shell

#!/bin/bash
#using basename with $0 parameter
#echo 'hello,world'
echo "this costs   \$15"
echo HOME : $HOME
var1=test1
num1=11
echo "$var1 $num1"
var1=test2
num2=22
echo "$var1 $num2"
date_=`date`
echo "today is "$date_
#ls /usr/bin -l > `date +%y_%m_%d_%H_%M_%S`.log
var3=20
var4=10
res1=`expr $var3 / $var4`
echo $res1
#res2=$[ $var3 / $var4 ]
#echo $res2
if date
then
   echo "it works"
else
   echo "no works"
fi
var5=20
var6=21
if [ $var5 -gt $var6 ]
then
	echo "$var5 > $var6 "
else
	echo "$var5 <= $var6"
fi
if [ $var5 -ne $var6 ]
then
	echo "no equal"
fi
var7=test111
var8=test111
if [ $var7 = $var8 ]
then
  echo same
else
 echo no same	
fi
if [ -n "$var7" ]
then
  echo "$var7 is not empty"
fi
if [ -d $HOME ]
then
	echo "is_dir"
else
    echo "no dir"	
fi
if [ -O /etc/passwd ]
then
 echo "you are owner"
else
 echo "you are not owner"	
fi
if (( $var6 < 0 ))
then
 echo "$var6<0"
else
 echo "$var6>=0"
fi
if [[ $USER=r* ]]
then
  echo "reg ok"
fi
case $USER in 
root)
  echo 'root';;
test)
  echo 'test';;
*)
  echo 'default';;
esac
for test in a b c d e
do
 echo $test
done
echo $test
IFS=$'\n'
for test in `cat /etc/passwd`
do
	echo $test
done
for file in /tmp/*
do
 if [ -d "$file" ] 
 then
  echo "$file is dir"
 elif [ -f "$file" ]
  then
  echo "$file is file	"
 fi 
done
#for(( a = 0 ; a <= 10 ; a++ ));
#do
	#echo "test num $a"
#done
#for (( i=0; i<10; i++)); do  
#echo $i  
#done
var9=10
while [ $var9 -gt 0 ]
do
  echo $var9
  var9=`expr  $var9 - 1 `	
done
par=$#
echo "\$0 =`basename $0`; \$1 =$1 ;there is $# parameters;last parameter is $par"
for param in "$*"
do
	echo "\$* param #$count=$param" 
done
count=1
cat 1.txt | while read line
do
	echo "line $count : $line"
        count=` expr $count + 1 `	
done
echo 'finished'
echo "error">&2
echo "normal"
exec 2>testerror
exec 1>testout
if read -s -t 5  -p  "enter a number :" n
then
 echo "you enter is $n"
else
 echo 
 echo "slow man"
fi


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值