0

I would like to display a message when calling custom_script -h currently my simple script is using sed stream editor and when trying something like :

sed -i "myscript_here"
if [ "$1" == "-h" ]; then
  echo "Usage: `custom_script $0` [Help_message_here]"
  exit 0
fi

Then I'm getting sed's message first and only then my help message

sed: invalid option -- 'h'
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

  -n, --quiet, --silent
                 suppress automatic printing of pattern...................

............................
''''''''''''''''''''''''''''
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
sed: no input files
/usr/local/bin/comment.sh: line 5: custom_script: command not found
**Usage:  [Help_message_here]**

How can I omit/hide sed's message and display only mine help message ?

2

1 Answer 1

1

As Fred suggested you'd better put your sed command inside IF in your case to display a simple help message you may do:

#!/bin/sh
if [[ "$1" == "-h" || "$1" == "--h" || "$1" == "-help" || "$1" == "--help" ]]; then
  echo "Usage: [Help_message_here]"
else
  sed -i your_script_here
exit 0
fi
Sign up to request clarification or add additional context in comments.

Comments