Home > Software engineering >  Display message when variable is not a valid filename or directory
Display message when variable is not a valid filename or directory

Time:11-14

I want to display a message when the variable fl is not a valid filename or directory. Seems as though there is a problem with the construct below.

if [[ ! -f "$fl" || ! -d "$fl" ]]; then
  printf '%s\n' "$fl: File or Directory does not exist"
fi

CodePudding user response:

if [ ! -e $fl ]; then
  printf '%s\n' "$fl: File or Directory does not exist"
fi

If you give it a filename remember to include the extension

CodePudding user response:

Thanks to @Barmar, who suggested using &&.

  • Related