note of SHELL (三)

#----------------------------------------------------
#name:time_counter.sh
#note:echo time escape
#!/bin/sh

time=$1
argc=$#
if [ ! $argc -eq 1 ] ;then
  echo -e "usage:$0 time_remain/n"
  exit 1
fi

if [[ $time -le 30 ]] &&  [[ $time -gt 0 ]] ;then
  sleep 1
while [[ $time -gt 0 ]]  ;do
  if [[ $time -le 30 ]] && [[ $time -ge 20 ]] ;then
  echo -e "***$time***/n"
  fi

  if [[ $time -lt 20 ]] && [[ $time -ge 10 ]] ;then
  echo -e "**$time**/n"
  fi

  if [[ $time -lt 10 ]] && [[ $time -gt 0 ]] ;then
  echo -e "*$time*/n"
  fi

  sleep 1
  ((time=$time-1))

  done

 else
   echo -e "time must between 0 and 30/n"
  fi
  
############################################
#scriptname:dater.sh
#purpose:echo all the date information
#!/bin/sh
set `date`
while [[ $# -gt 0 ]] ;do
  echo $1
  shift
done

#-----------------------------------------
#name:debug_echo.sh
#note:using echo for debuging
#!/bin/sh
debug=0
debecho()
{
  if [ ! -z $debug ] ;then
   echo $1
   fi
}

debecho "hi all"

#####################################################
#scriptname:show_all_arg.sh
#purpose:echo all the arguments
#!/bin/sh
for arg in $@ ;do  # $@ is same as $*
  echo -e "$arg/n"
  done

#-----------------------------------------------------------
#srcipt:monitor.sh
#purpose:monitor a process and print its status in current
#!/bin/sh
process=$1
argc=$#
if [[ !$argc -eq 1 ]] ;then
  echo -e "usage:$0 process_to_check/n"
  exit 1
fi
while true
do
  ps -ef |grep -v "grep $process"|grep -v "monitor.sh"|grep $process>/dev/null
  status=$?
  if [[ $status -eq 0 ]] ;then
    echo -e "$process is running/n"
    else
      echo -e "$process is  not  running/n"
  fi
  sleep 1
done

 

###################################################################
#scriptname:month.sh
#purpose:using for loop twice
#!/bin/sh
for month in Jan Feb Apr Mar May Jun Jul Aug  Sep Oct Nov Dec
do
  echo -e "Do you want to process $month(y/n)/n"
  read ans
  if [ "$ans" = n ] ;then
    continue
  else
    for week in 1 2 3 4
  do
  echo -e "Do you want to process $week week(y/n)/n"
  read ans2
  if [ "$ans2" = n ] ;then
    continue
    else
    echo -e "Processing $month the $week week/n"
    sleep 1
    echo -e "Processing complete!/n"
    exit
  fi
  done
  fi
done

 

#-------------------------------------
#name:msg.sh
#note:usage of "here document"
#/bin/sh
personal_msg()
{
  read name
  read home
  read tel
}

personal_msg<<msg
peter
wuhan
027
msg

echo -e "name:$name/n home:$home/n tel:$tel/n"

 

#-----------------------------------------------
#name:multiply.sh
#note:show the result of multiply
#!/bin/sh
 result=1;
  
  until [ -z "$1" ] ;do
  let "result *= $1"
  shift
  done
  

  echo -e "the result is $result/n"
    
  

 

#---------------------------------------------------
#
#
#!/bin/sh
if [ $UID -eq 0 ] ;then
  echo -e "you are root!/n"
  else
  echo -e "please switch to root account!/n"
  fi
SUCCESS=0
 a=`grep -q "hi" test`
  if [  $a -eq $SUCCESS ] ;then
    echo -e "It is contain "hello"/n"
    else
    echo -e "no result/n"
    fi

 

 

#-------------------------------------
#
#
#!/bin/sh
#name:guess.sh
#note:guess game
if [ ! -z $1 ] ;then
  filename=$1
  else
    filename="test.txt"
    fi

count=0
while [ "$name" != "peter" ] ;do
  read name
  let count=count+1
  done<$filename
 echo -e "you guess" $count "times/n"

 

 

#######################################
#script:hour.sh
#purpose:echo a string each hour
#!/bin/sh
hour=0
while [[ $hour -lt 23 ]] ;do
  case $hour in
  [0-9]|1[0-1])
  echo -e "good moring/n"
  ;;
  12)
  echo -e "lunch time/n"
  ;;
  1[3-8])
  echo -e "good afternoon/n"
  ;;
  *)
  echo -e "good evening/n"
  ;;
  esac
  ((hour+=1))
done

 

 

###################################################
#scriptname:IFS.sh
#purpose:IFS used to separate a string with whitespace
#!/bin/sh
IFS=":"
string="peter:mike:geogre"
#string2="peter mike geogre"
for name in $string ;do
  echo -e "$name/n"
done
old="$IFS"
IFS="$old"

set 1 2 3 4
for name2 in $* ;do
  echo -e "$name2/n"
done

 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值