![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing runtime arguments to a shell script... | santy | Shell Programming and Scripting | 10 | 01-09-2009 10:47 PM |
| Passing arguments to a shell script from file while scheduling in cron | weblogicsupport | SUN Solaris | 4 | 01-27-2008 11:16 PM |
| Passing blank arguments to a script | rm-r | UNIX for Advanced & Expert Users | 7 | 01-08-2008 08:56 PM |
| Passing arguments to a Perl script | jyoung | Shell Programming and Scripting | 4 | 12-29-2004 05:57 PM |
| passing arguments | jpprial | UNIX for Dummies Questions & Answers | 4 | 04-03-2001 11:13 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Passing arguments to a script
I've written a script (bgrep) for a more advanced grep command (& attached a cut down version below). I'm trying allow all grep options to be used, or in any combination.
The script works fine if I type say bgrep -i -files product it will return a non-case sensitive list of matches for product however if I type bgrep -in -files product I get the same list & no line numbers. I know why this is happening, it's because the -n option is a valid option for the echo command I am using. I not sure how to get round this. Is there some other command I could use. I'd appreciate any advice, feel free to criticise. Code:
#!/bin/sh
>grep_args
files=false
forms=false
text=""
while [ $# -gt 0 ]
do
case "$1" in
-?) echo $1 > bgrep.tmp
paste -d" " bgrep.tmp grep_args > grep_args.tmp
mv grep_args.tmp grep_args;;
-files) files=true;;
-forms) forms=true;;
-*) echo "usage :$0 [-grepoption] [-files] [-forms] text"
exit 1;;
*) text=$@
break;;
esac
shift
done
if [ $files = true ]
then
echo files:
find . -name "*.f" -print|xargs grep `cat grep_args` "$text"|pg
fi
if [ $forms = true ]
then
echo forms:
find . -name "*.s" -print|xargs grep `cat grep_args` "$text"|pg
fi
Last edited by Perderabo; 06-14-2002 at 08:54 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|