Check if an argument is a path
bash
Solution
You can get last argument using variable reference:
numArgs=$#
lastArg="${!numArgs}"
# check if last argument is directory
if [[ -d "$lastArg" ]]; then
echo "it is a directory"
else
echo "it is not a directory"
fi
Problem
I'm writing a script in bash. It will receive from 2 to 5 arguments. For example: `./foo.sh -n -v SomeString Type Directory` -n, -v and Directory are optional. If script doesn't receive argument Directory it will search in current directory for a string. Otherwise it will follow received path and search there. If this directory doesn't exist it will send a message. The question is: Is there a way to check if the last arg is a path or not?