Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, i was wondering if someone could help me figure out a script for global variables i'm trying to set for a group of command line arguments: basically i'm trying ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    3

    bourne script help


    Hi, i was wondering if someone could help me figure out a script for global variables i'm trying to set for a group of command line arguments:

    basically i'm trying to set:

    if $# = 3

    then i want to search for each all string $1 $2 $3

    if $# = 4

    then i want to search for each all string $1 $2 $3 $4

    any ideas?

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    648
    Are you restricted to have it be "Borne Shell" or is "BASH" okay?

    What do you mean by search? Is it a grep searching for 3 or 4 patterns?

  3. #3
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    648
    For example if the need to grep a file for "patterns" in Bourne.
    Code:
    case $#; in
       3)    grep -E "$1|$2|$3" search_on_filename_or_list
       ;;
       4)    grep -E "$1|$2|$3|$4" search_on_filename_or_list
       ;;
    esac
    If Bash is okay:
    Code:
    grep -E "'$(IFS='|' && echo "$*")'" search_on_filename_or_list

Posting Permissions

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