LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I am a newbie, help me (https://www.linuxquestions.org/questions/linux-newbie-8/i-am-a-newbie-help-me-353694/)

yaadhav 08-16-2005 01:19 AM

I am a newbie, help me
 
Using patterns with case

I wan to write a command called (odd), which uses a case statement to determine the number of parameters passed to it (it’s not important what these parameters are). If no parameters are passed, print out “wrong”, if one parameter, print out “one”, if two parameters, print out “two”, and if three or more parameters, print out “many”.

I hope u guys can help me. Thx :)

Emmanuel_uk 08-16-2005 01:25 AM

See
http://linux-pdf.xs4all.nl/data/alge...20Tutorial.pdf

Bash will tell you how many arguments you gave to a bash script

I quote
$# holds number of arguments specified on command line. and $* or $@ refer to all the arguments passed into the script.

You have the echo command to output text
You have a if syntax
You can do some math with bash (you may want to use "modulo")

If you want more info at a later date
man bash
or look for the advanced bash-scripting guide

Oh, yes, was going to forget, please make the title of the thread
more meaningful next time. Thanks

trickykid 08-16-2005 06:37 AM

And on a side note, read this post about your undescriptive/unhelpful thread title and how to improve on it: http://www.linuxquestions.org/questi...95#post1730795

slapNUT 08-17-2005 02:21 AM

tricky
You forgot to warn about getting homework help. This smells like educational assignments to me. I love homework!

#!/bin/bash
ARGS=( wrong one two many )
NUMS="$#"
echo "You passed ${ARGS[$NUMS]} arguments to this script"
echo "Have a nice day."

Emmanuel_uk 08-17-2005 02:27 AM

I did think that, so I tried not to be too forthcoming with information.
Although I was nice :-)

yaadhav, I hope you come clear and tell us if it was an assignment

In the process you will have learned something about bash hopefully

Cannot wait to see your script...


All times are GMT -5. The time now is 07:08 AM.