0

I know how to check for a file in bash using this code

file=$1

if [ -f "$file" ]
then
...
fi

But I want to do something when it's not a file.

file=$3

if [ "$1" == "" ] || [ "$2" == "" ] || [ $file is not a file??? ]
then 
echo "use: notEmpty notEmpty file"
fi

Can anyone help me out?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Joey
  • 154
  • 5
  • 18
  • 1
    Possible duplicate of [Check if a directory exists in a shell script](http://stackoverflow.com/questions/59838/check-if-a-directory-exists-in-a-shell-script) – Remigius Stalder Dec 12 '15 at 12:11

1 Answers1

1
if [ "$1" == "" ] || [ "$2" == "" ] || [ ! -f "$file" ]

The whitespaces after [ and before ] are important.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Ok thank you but ny actual question was how to do the $file is not a file part? – Joey Dec 12 '15 at 12:10
  • The `!` preceding `-f` negates the test, so the last `[` command succeeds if `$file` is *not* a file. – chepner Dec 12 '15 at 15:01