Solved

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

Posted on 2004-08-19
9
250 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 500 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

Industry Leaders: 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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

729 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