I’m having trouble taking in a path where to run the script as a command line argument, test is it exists, then changing to that path to perform work. Here what I’m trying:
#!/bin/bash
scriptpath=$1
if [ $# -lt 1 ]
then
echo "Usage: script.sh <directory_name>"
fi
if [ -d scriptpath ]
then
# work......
else
echo "Directory does not exist"
fi
Change this:
to this:
Also, I recommend making use of
"", so that your script still behaves properly when the argument contains weird characters. (Unix allows spaces, newlines, asterisks, even control characters inside filenames.) So: