Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Posts
    11

    Unanswered: 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.

  2. #2
    Join Date
    May 2007
    Location
    Milano, Italy
    Posts
    22
    Works for me, could you post the output with -xv?

  3. #3
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •