The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-28-2008
kim187 kim187 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 8
is this script right???

my friend has challenged me to this


shell program,count85, that reads the command line arguments, counts the number of

options (those arguments that start with a - , and counts the number of arguments (those

arguments that do not start with a -. (hint use case ... -*) *) )

Output all of the options on one line and all of the arguments with their counts on another line.


#!/bin/bash
# next echo to show the input
echo "here comes $*"
for i in $*
do
if echo $i | grep ^- > /dev/null
# the echo and | above is because grep looks
# for data in a file or stdin not in a variable
# grep ^- $i would not work
then
echo "$i is an option"
else
echo "$i is an argument"
fi
done
echo "done with optiontest with $*"
# summation and data passed for info only

dont know if i did it right or not

output is

here comes
done with optiontest with


is my if then else statement not correct

thanks

airmax_sk@yahoo.com

Last edited by kim187; 04-28-2008 at 09:25 PM.. Reason: change