LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-09-2005, 06:58 AM   #1
lukea37
LQ Newbie
 
Registered: Sep 2005
Posts: 1

Rep: Reputation: 0
What is wrong with the following script?


#!/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" (c)
then print $i
fi
let tc=tc+c n=0 c=0
done

if test "$cflag"
then print $tc
fi
let tc
 
Old 09-09-2005, 07:29 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
you're supposed to tell us.
 
Old 09-09-2005, 08:46 AM   #3
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
Probably it doesn't work as expected
Please use CODE-tags when posting source code, it makes the code much more readable.
 
Old 09-09-2005, 08:49 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
or perhaps the expectations are incorrect
 
Old 09-10-2005, 08:34 AM   #5
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Why do you think something's wrong with it?
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Could someone tell me what's wrong with my shell script please? RowanB Programming 4 11-11-2004 11:17 PM
Whats wrong with this script??? Sammy2ooo Linux - Networking 2 08-24-2004 06:20 AM
What's wrong with my iptables script? veritas Linux - Security 3 06-06-2004 11:39 AM
My first BASH script, what's wrong with it? szf2 Linux - Newbie 2 11-12-2003 01:43 PM
What's wrong with my script ? kalmen Linux - General 6 12-28-2002 06:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration