shell if [] 条件 and read

 Recent week  I deal with the shell script met many problem.

 firstly  ksh has some grammar different with bash,so you much well know what sh type you deal with.

 

 about ksh if condition should take care of

 

  if [[ $line == $xslSignBegin ]]; then

  echo "$line"

  fi

1. there is space between if and "[[" ,  operators and "==" , "[[ "and operators,"]] "and operator ,";" and then

(so many spaces)

2.use "=" if you don't have space in operator . and bash use = not ==

 

 the following three days I done a shell

 if you met a problem between like test:unknown operator try ' '

 

 

#!bin/ksh

 

mozillaDir=/usr/share/mime/packages
fileName=freedesktop.org.xml
fileNameBack=freedesktop.org.xmlback

if [ ! -f $mozillaDir/$fileNameBack ]; then
 
 if [ 'id 2> /dev/null | cut -d"=" -f2 2> /dev/null | cut -d"(" -f1 2> /dev/null' ]; then
  cp $mozillaDir/$fileName   $mozillaDir/$fileNameBack
  xslSignBegin="<mime-type type=/"text/x-xslt/">"
  commentBegin="<!--"
  commentEnd="-->"
  xslSignEnd="</mime-type>"
  isEdit=false
  addComment=false
  while read line
  do
         
    if [[ $line == $xslSignBegin ]]; then
     isEdit=true
     addComment=true
     line=$commentBegin$line
      
    elif [[ $addComment = true && $line == $xslSignEnd ]]; then
     line=$line$commentEnd
     addComment=false
    fi
    echo "$line" >> $mozillaDir/temp
  done < $mozillaDir/$fileName
  if [[ $isEdit = true ]]; then
   mv $mozillaDir/$fileName   $mozillaDir/$fileName"update"
   mv $mozillaDir/temp   $mozillaDir/$fileName
   rm $mozillaDir/temp
   isEdit=false
      echo "exectue command update"
   update-mime-database /usr/share/mime
  fi
 else
  echo "You should switch root user to config Mozilla environment to support text//xsl MIME  type or change  firefox browser in order to run successfully!"
 fi
fi 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值