[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-08-19
9
Medium Priority
?
255 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
  • 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
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!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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…
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.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 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