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

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.
seremazAsked:
Who is Participating?
 
lemmeCConnect With a Mentor Commented:
if [ -d $1 ]
then
echo Directory
fi

would print directory if the first argument is a directory.
0
 
lemmeCCommented:
$# gives the number of command line parameters. $1, $2, etc. are the first, second, etc. arguments
0
 
avizitCommented:
if test -d $1  

to check if first parameter is directory
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
avizitCommented:
remove the "test" .. anyway  lemmec posted the correct answer
0
 
seremazAuthor Commented:
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
 
lemmeCCommented:
Use nested ifs. Is this homework?
0
 
seremazAuthor Commented:
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
 
lemmeCCommented:
You are welcome. But is a 'B' grading justified?
0
 
seremazAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.