Reputation: 669
Im Trying to Execute a Command if Two Files Exist on a Location
If Only Either One of Two File Exist Script must Execute another different command here is the script i tried
if [ -e /Users/NJ/Library && /Users/NJ/Desktop ];then
echo both
else
echo single
fi
Upvotes: 1
Views: 3023
Reputation: 669
if [ -e /Users/NJ/Library ] && [ -e /Users/NJ/Desktop ] ;then
echo both
else
echo single
fi
Upvotes: 0
Reputation: 1478
You can use a double bracket insted of a simple :
if [[ -e /Users/NJ/Library && -e /Users/NJ/Desktop ]] ;then
echo both
else
echo single
fi
Upvotes: 0
Reputation: 20980
if [ -e "/Users/NJ/Library" -a -e "/Users/NJ/Desktop" ];then
....
the [ condition ]
evaluator uses -a for AND & -o for OR. Here is a manual.
OR use below syntax.
if [ -e "/Users/NJ/Library" ] && [ -e "/Users/NJ/Desktop" ];then
....
Upvotes: 1
Reputation: 7092
You need to separate the tests into their own square brackets:
if [ -e file ] && [ -e file ]; then
echo "wow"
fi
Upvotes: 4