LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to add -h parameter in script (https://www.linuxquestions.org/questions/programming-9/how-to-add-h-parameter-in-script-161536/)

yulitao 03-23-2004 05:58 PM

how to add -h parameter in script
 
I have a script is "myscript",what shold I do if I want it show some help information when I run mysciprt -h!!!!!Thanks, I am a beginer!

zekko 03-23-2004 06:13 PM

Depending what language you're doing it in? More information please.

yulitao 03-23-2004 06:15 PM

bash shell in redhat

Hko 03-23-2004 06:42 PM

Code:

#!/bin/bash

NAME=$(basename $0)
if [ "$1" == "-h" ] ; then
        echo "Usage:  ${NAME} [-h]"
        echo "Option:"
        echo "  -h:  Print this help text"
        exit 0
fi
echo "You gave me these arguments: $*"
exit 0


aluser 03-23-2004 07:30 PM

You might also want to "man 1 getopt" for a more general way of taking comand line arguments. Unfortunately it's a little long and my system doesn't seem to have the examples mentioned in the doc :(


All times are GMT -5. The time now is 04:53 AM.