Reputation: 261
I'm creating a bash script, but it does not seem to check if a folder exists, when it's based on variables. Although the folder does exists, when I cd into it.
#!/usr/bin/env bash
VAR1="/Users/nameuserhere/Desktop/";
VAR2=`date "+%Y-%m-%d"`;
VAR3="$VAR1$VAR2";
echo "folder path: $VAR3";
if [[ -f "$VAR3" ]]
then
echo "this/not does exists"
else
echo "this/not does not exist"
fi
Upvotes: 0
Views: 726
Reputation: 69208
Use -d
, as -f
check if it's a file:
-f FILE True if file exists and is a regular file
Upvotes: 2