muugua 发表于 2018-8-30 06:03:39

一些基本的shell脚本

  IF 语句
  ifcondition
  then
  statements
  ...
  [ elif condition
  then
  statements
  ... ]
  [ else
  statements
  ... ]
  fi
  其中“[]”是test命令并不是必须的
  if grep foo myfile &> /dev/null;then
  for example:
  #!/bin/bash
  DIR="/tmp"
  iftest$DIR ; then
  echo "This isa directory"
  else
  echo "This isnot a directory"
  fi
  上面的例子也可以写成如下:
  #!/bin/bash
  DIR="/tmp"
  if[-d$DIR];then
  echo "This isa directory"
  else
  echo "This isnot a directory"
  fi
  扩展 :
  #!/bin/bash
  DIR="/tmp/"
  if test -d $DIR ;then
  echo "this is a dircetory"
  eliftest -f $DIR ; then
  echo "this is a file"
  else
  echo "this is neither a directory nor a file"
  fi

页: [1]
查看完整版本: 一些基本的shell脚本