bash - How to tell if a filename is a directory, not a file -


i need check if parameter passed bash script folder or file. may or may not end /

xpath=$(dirname "$1") 

strips out dirname if there no trailing /

thanks

given file a , dir t.

you can use command file:

$ file t t: directory $ file a: ascii text 

or -f (file) , -d (dir) flags.

$ [ -f ] && echo "this file" file $ [ -f t ] && echo "this file" $ $ [ -d t ] && echo "this dir" dir $ [ -d ] && echo "this dir" $ 

Comments