The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-14-2002
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
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..
  #2 (permalink)  
Old 06-14-2002
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
Sorry about the indenting, it seems to have been lost in the cut & paste from my system
  #3 (permalink)  
Old 06-14-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
I edited your post to include code tags. This fixed the indenting.

I think that
echo "" $1
will fix your problem.
  #4 (permalink)  
Old 06-14-2002
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
Yeah, it works now - should have thought of that really.

Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0