Thursday 29 March 2018

Shell script to check whether the given input is a file or directory

#Shell script to check whether the given input is a file or directory
for i in $*
do
    if  test -d $i
    then         
        echo "$i is a directory file"
    elif test -f $i
    then
        echo "$i is an ordinary file"
    else
       echo "$i does not exist"
    fi
done



OUTPUT
csc@csc-SVE1513CYNB ~ $ sh fcheck.sh sxc well sasha
sxc does not exist
well is an ordinary file
sasha is a directory file

No comments:

Post a Comment