[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

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.
0
seremaz
Asked:
seremaz
  • 4
  • 3
  • 2
1 Solution
 
lemmeCCommented:
$# gives the number of command line parameters. $1, $2, etc. are the first, second, etc. arguments
0
 
lemmeCCommented:
if [ -d $1 ]
then
echo Directory
fi

would print directory if the first argument is a directory.
0
 
avizitCommented:
if test -d $1  

to check if first parameter is directory
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now