Find the answer to your Linux question:
Results 1 to 3 of 3
It is a shell script version of the grep command. #!/bin/ksh # Shell version of grep # vflag= xflag= cflag= lflag= nflag= arg=$1 set -f while true do case $arg ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    2

    Wots wrong with this script?


    It is a shell script version of the grep command.

    #!/bin/ksh
    # Shell version of grep
    #
    vflag= xflag= cflag= lflag= nflag= arg=$1
    set -f
    while true
    do
    case $arg in
    -v*) vflag=1;;
    -x*) xflag=1;;
    -c*) cflag=1;;
    -l*) lflag=1;;
    -n*) nflag=1;;
    -e*) shift; expr=$1"; arg=;; -e*) shift; expr=$1; arg=;;
    -f*) shift; expr=(< $1); arg=;;
    -*) print -u2 - $0: 'unknown flag'; exit 1;;
    *)
    if test "expr" = ''
    then expr="1"; shift
    fi
    test "$xflag" expr="*${expr}*"
    break;;
    esac
    arg=${arg#-?}
    case arg in
    "") shift; arg=$1;;
    *) arg=-$arg;;
    esac

    noprint=$vflag$cflag$lflag
    integer n=0 c=0 tc=0 nargs=$#
    for i in "$@"
    do if ((nargs<=1))
    then fname=''
    else fname="i"
    fi
    test "$i" && exec 0< $i
    while read -r line
    do let n=n+1
    case "$line" in
    expr)
    if test "$noprint" = ""
    then print -r "$fname${nflag:+$n:}$line"
    fi
    let c=c+1 ;;
    *)
    if test "vflag"
    then print -r "$fname${nflag:+$n:}$line"
    fi ;;
    esac
    done
    if test "lflag" ()
    then print $i
    fi
    let tc=tc+c n=0 c=0
    done

    if test "$cflag"
    then print $tc
    fi
    let tc

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,914
    Why dont you just use grep? Or are you just asking us to do your homework for you?
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Tell us why you think there's something wrong with it. (And please use "code" tags so we can see your indentation.)

  4. $spacer_open
    $spacer_close

Posting Permissions

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