cxs7225032 发表于 2018-8-23 10:54:46

shell---practice2

#!/bin/bash  
#File: for_dir.sh
  
#Date: 2016-01-12
  

  
changeFile="/tmp/mypasswd"   //定义changFile变量的值
  

  
if [ ! -f $changeFile ]; then   //判断changFile是否存在
  
      touch $changeFile
  
else
  
      echo "The $changeFile is exist."
  
fi
  

  
#if [ ! -x $changeFile ]; then   //此if语句为赋予权限,可以省略
  
#      chmod +x $changeFile
  
#else
  
#      echo "The $changeFile with executable permissons."
  
#fi
  

  
file="/etc/passwd"      //定义file变量的值
  

  
for i in 2 4 6 10 13 15   //将i做for循环,依次赋值2 4 6 10 13 15
  
do
  
      line=`sed -n "$i"p $file`   //取出对应的行,并赋值给变量line
  
      echo "$line"
  
      echo "$line" >> /tmp/mypasswd
  
done


页: [1]
查看完整版本: shell---practice2