Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Gilles Jul 31 '14 at 0:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
You are using -ne, which is for integer comparison. Just use [ ! "$1" == "--help" ] instead –  fedorqui Jul 30 '14 at 13:19

1 Answer 1

the parameter -ne is only valid for numbers, you have to use != for string comparism.

This works:

if [ $# -ne 2 ] ; then
  if [ "$1" != "--help" ]; then
    echo "ERROR: wrong number of parameters"
    echo
  fi
  echo "Syntax: $0 foo bar
  exit 1
fi
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.