shell-判断文件或目录是否存在

shell-判断文件或目录是否存在

   张吉吉     2021年2月26日 09:35     1137    

#!/bin/bash

#judge dir exists or not!

 

#判断目录是否存在,如果存在返回0,不存在返回1.

#judge_dir $1    $1表示路径

function judge_dir()

{

       if test -d $1

       then

              echo "this $1 is exists!"

              return 0

       else

              echo "this $1 is not exists"

              return 1

       fi

}

 

#判断文件是否存在,如果存在返回0,不存在返回1.

#judge_file $1    $1表示路径

 

function judge_file()

{

       if test -f $1

        then

                echo "this $1 is exists!"

              return 0

        else

                echo "this $1 is not exists"

              return 1

        fi

}


文章评论

0

其他文章