If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help with script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-13-07, 18:38
rfourn rfourn is offline
Registered User
 
Join Date: Jun 2007
Posts: 11
Help with script

I need help following this script:

#!/bin/sh
file=$1
shift
vi `grep -l "$file" "$@"`

when i run it i get nothing. does the 'shift' before the 'vi' command
remove the value of $1, thereby not allowing the script to finish or am
i missing something.
i removed the 'shift' line from the above script and i get an empty vi page.
i thought this script would open the file which matches the 1st argument
in the vi editor??
any help is appreciated.
Reply With Quote
  #2 (permalink)  
Old 06-14-07, 16:14
radoulov radoulov is offline
Registered User
 
Join Date: May 2007
Location: Milano, Italy
Posts: 22
Works for me, could you post the output with -xv?
Reply With Quote
  #3 (permalink)  
Old 06-21-07, 12:12
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Code:
file=$1
sets the variable file to the 1st param supplied.
Code:
shift
gets rid of this first param and just leaves the rest of the params in $@
Code:
grep -l "$file" "$@"
grep searches for a string in a file. The -l option just lists the file names it's in. The odd thing is the string to search for is in the variable $file and the file name it is searching is in the variable $@, if this contains more than 1 value (which it might if you typed in say 3 params) it will cause an error.
Code:
vi `grep -l "$file" "$@"`
The backwards single quotes will run the command just mentioned and then pass those file names to vi for you to edit.

It seems a complicated way of not doing anything very interesting. Why were you running it anyway? what were you trying to do?

Mike
Reply With Quote
  #4 (permalink)  
Old 06-21-07, 16:38
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Quote:
Originally Posted by rfourn
I need help following this script:

#!/bin/sh
file=$1
shift
vi `grep -l "$file" "$@"`

when i run it i get nothing. does the 'shift' before the 'vi' command
remove the value of $1, thereby not allowing the script to finish or am
i missing something.
i removed the 'shift' line from the above script and i get an empty vi page.
i thought this script would open the file which matches the 1st argument
in the vi editor??
any help is appreciated.
Same as
Code:
#/bin/sh
vi `grep -l "$@"
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On