Sample Header Ad - 728x90

Empty string is a file? ( if [ ! -f "" ] )

0 votes
1 answer
4579 views
The script is called **isFile.sh** and looks like this:
#!/bin/sh

echo $1
echo $2

if [ ! -f $1 ]; then
  echo "$1 (arg1) is not a file"
fi

if [ ! -f $2 ]; then
  echo "$2 (arg2) is not a file"
fi
First I created a file by doing touch file.exist. And I ran bash isFile.sh file.exist file.notexist The output was: >file.exist > >file.notexist > >file.notexist (arg2) is not a file ---------------------------------------------------- Then I ran bash isFile.sh "" file.notexist The output was: >(# empty line) > >file.notexist > >file.notexist (arg2) is not a file Expected output is: >(# empty line) > >file.notexist > >(arg1) is not a file > >file.notexist (arg2) is not a file Can somebody explain why?
Asked by SoloKyo (41 rep)
Aug 7, 2018, 04:44 AM
Last activity: Jun 3, 2024, 10:33 AM