[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Creating a BSH which outputs the number of parameters on the command line

Posted on 2004-08-19
9
Medium Priority
?
253 Views
Last Modified: 2010-04-21
I Need to create a bourne shell script program that outputs how many parameters were given on the command line, and if there was one or more parameters given the program should report to the user if the first parameter exists as a directory or not.

Any help or nudge in the right direction? thanks alot.
0
Comment
Question by:seremaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 5

Expert Comment

by:lemmeC
ID: 11841672
$# gives the number of command line parameters. $1, $2, etc. are the first, second, etc. arguments
0
 
LVL 5

Accepted Solution

by:
lemmeC earned 1500 total points
ID: 11841727
if [ -d $1 ]
then
echo Directory
fi

would print directory if the first argument is a directory.
0
 
LVL 11

Expert Comment

by:avizit
ID: 11841746
if test -d $1  

to check if first parameter is directory
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:avizit
ID: 11841755
remove the "test" .. anyway  lemmec posted the correct answer
0
 

Author Comment

by:seremaz
ID: 11841784
thats great, how would i first check how many parameters were given, and if this is greater than one THEN report if the first parameter is a directory?
0
 
LVL 5

Expert Comment

by:lemmeC
ID: 11841795
Use nested ifs. Is this homework?
0
 

Author Comment

by:seremaz
ID: 11841815
this is a small base to a piece of coursework, the main coursework itself is creating a large test plan and test issues for the program, thankyou for your help
0
 
LVL 5

Expert Comment

by:lemmeC
ID: 11841845
You are welcome. But is a 'B' grading justified?
0
 

Author Comment

by:seremaz
ID: 11841875
of course, as i said this is the base for the main test plan so as long as i'm on the right lines ill be fine... i just needed to be on the right line, and you put me there, thanks again :-) you've been a large help
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question