?
Solved

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

Posted on 2004-08-19
9
Medium Priority
?
252 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Technology Partners: 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!

Question has a verified solution.

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

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…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 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