Linux基础11_条件判断及回圈

来源:互联网 发布:滑窗的方法 数据分析 编辑:程序博客网 时间:2024/06/03 22:49

vi sh06.sh

#!/bin/bash

read -p"Please input (Y/N): " yn

if ["$yn" == "Y" ] || [ "$yn" == "y" ];then

    echo "OK, continue"

    exit 0

fi

if ["$yn" == "N" ] || [ "$yn" == "n" ];then

    echo "Oh, interrupt!"

    exit 0

fi

echo "I don'tknow what your choice is" && exit 0



vi sh07.sh

#!/bin/bash

s=0

i=0 

while [ "$i" !="100" ]

do

  i=$(($i+1))  

  s=$(($s+$i))

done

echo "The result of'1+2+3+...+100' is ==> $s"

 

 

 

 

 

 

 

 

 

 

 

 

vi sh18.sh

#!/bin/bash

read -p "Please input adirectory: " dir

if [ "$dir" =="" -o ! -d "$dir" ]; then

   echo "The $dir is NOT exist in your system."

   exit 1

fi

filelist=$(ls $dir)     

for filename in $filelist

do

   perm=""

   test -r "$dir/$filename" && perm="$permreadable"

   test -w "$dir/$filename" && perm="$permwritable"

   test -x "$dir/$filename" && perm="$permexecutable"

   echo "The file $dir/$filename's permission is $perm "

done

 

 

 

shell 的追踪

sh -n sh07.sh      不运行script,仅查询语法问题

sh -v sh07.sh       先在屏幕显示sh07.sh的内容,再运行

sh -x sh07.sh      讲sh07.sh的全部运行过程列出来  





0 0