LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-16-2005, 02:19 AM   #1
yaadhav
LQ Newbie
 
Registered: Aug 2005
Location: I live in a world full of anger and hate
Posts: 3

Rep: Reputation: 0
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
 
Old 08-16-2005, 02:25 AM   #2
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,605

Rep: Reputation: 53
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

Last edited by Emmanuel_uk; 08-16-2005 at 03:19 AM.
 
Old 08-16-2005, 07:37 AM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 234Reputation: 234Reputation: 234
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
 
Old 08-17-2005, 03:21 AM   #4
slapNUT
Member
 
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144

Rep: Reputation: 15
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."
 
Old 08-17-2005, 03:27 AM   #5
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,605

Rep: Reputation: 53
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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
security newbie, but not Linux newbie. advice on secure delete tools mattie_linux Linux - Security 19 08-15-2005 02:50 AM
Linux semi-newbie and Wine vary newbie geovolt_os1 Linux - Software 4 04-19-2005 12:03 PM
newbie;I am a linux newbie who has installed slackware and have run into a few proble MollyJolly Slackware - Installation 6 06-01-2004 12:21 PM
How To Update To Slackware-Current For a Newbie, By a Newbie :) windsok Slackware 1 09-18-2003 09:53 PM
ipchains newbie. Kernel newbie skeletal29 Linux - Security 3 06-02-2002 04:30 AM


All times are GMT -5. The time now is 04:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration