This question already has an answer here:
- Comparing two strings in Bash 3 answers
My script needs two arguments. I want to hide the error message if someone calls the script with
script.sh --help
so I tired this:
if [ $# -ne 2 ] ; then
if [ "$1" -ne "--help" ]; then
echo "ERROR: wrong number of parameters"
echo
fi
echo "Syntax: $0 foo bar
exit 1
fi
But I get the error
script.sh: line 10: [: --help: integer expression expected
What is wrong?
-ne
, which is for integer comparison. Just use[ ! "$1" == "--help" ]
instead – fedorqui Jul 30 '14 at 13:19