Reputation: 85
I am getting an error in my bash script and I don't see anything wrong with it. Here is the code that is giving me the error.
if [ "$password" = "na" ]; then
log "Password not set"
usage
exit 1
fi
Could anyone see anything wrong with this? It looks fine to me but I am also pretty new to bash in general.
EDIT: Here are the previous lines of code, maybe that will help.
if [ "$SITE" = "unknown" ]; then
log "Site not set"
usage
exit 1
fi
if [ "$VERSION" = "na" ]; then
log "Version not set"
usage
exit 1
fi
if [ "$password" = "na" ]; then
log "Password not set"
usage
exit 1
fi
Upvotes: 1
Views: 1260
Reputation: 2061
Your example works without errors for me. I will guess that your file may contain 'hidden' characters (most likely a '\r' - carriage return - but could be something else). Use to native Vi/Vim family of editors to avoid this; otherwise, check the settings in your text editor and set your 'line endings' to Unix/OSX. Try this:
tr -d '\r' /path/your_file.sh > /path/your_file.mod.sh
bash -n /path/your_file.sh ## should show error
bash -n /path/your_file.mod.sh ## no errors
:)
Dale
Upvotes: 2