2007年7月4日 星期三

shell script : test file type

[will@localhost ShellScript]$ cat testfile.sh
#!/bin/sh

read -p "Input a filename : " filename

test -z $filename && echo "You MUST input a filename." && exit 0

test ! -e $filename && echo "The filename $filename DO NOT exist" && exit 0

test -f $filename && filetype="regulare file"
test -d $filename && filetype="directory"
test -r $filename && perm="r"

test -w $filename && perm=$perm"w"

test -x $filename && perm=$perm"x"

echo "The filename: $filename is a $filetype"
echo "And the permission are : $perm"

[will@localhost ShellScript]$

沒有留言:

網誌存檔

關於我自己