Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
HELP!!! Let script accept arguments
Name: Arne Matthijssen Date: March 31, 2003 at 23:39:03 Pacific OS: Sun CPU/Ram: unknown/unknown
Comment:
Hi all,
I am writing a unix script and am desperately trying to have it accept parameters not using the $1, $2,.. $9 way but by allowing arguments on the command line, e.g. "call_script -name John -age 24" instead of "call_script John 24"
in bash 2.03...
Can't find out how to do it... but it must be possible...
# Use getopts to scan for -e/-w/-p/-f [filename]: # (':' after option letter indicates arg expected. # Leading ':' in optstring suppresses default error messages.) error_level='ERROR' # Default prompt_for_comments='FALSE' # Default while getopts ":ewpf:" opt; do case $opt in e ) error_level='ERROR' ;; w ) error_level='WARNING'; message_prefix='Warning: ' ;; p ) prompt_for_comments='TRUE' ;; f ) filename=$OPTARG ;; * ) print -u2 'fcheck: invalid option.'; exit 1 ;; esac done shift $(($OPTIND -1))
Note a couple of limitations though: * You can only parse single-letter flags, e.g. "-a 24", not "-age 24" * If an invalid option is passed, there is no straightforward way AFAIK to display the offending option, since "$opt" just gives "?".
0
Response Number 3
Name: nails Date: April 1, 2003 at 06:52:09 Pacific
Summary: I have following requirements in C shell script: - The script accepts the date input - Upon accepting the date, the script needs to list all the files greater than date inputted Also, someone throw m...
Summary: Hi, I have a file in the format of a listing of item numbers in one column in the (*.xls) -excel file. I would like to have an output in a different format. example: my input will be in the form HEDM...
Summary: below is the script so far....i had some help with this...and was wondering if anyone here could be of any further assistance.... what i want to do is when this is run...is to send anyone who is onlin...