Solved

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

Posted on 2004-08-19
9
237 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
Comment Utility
$# 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
Comment Utility
if [ -d $1 ]
then
echo Directory
fi

would print directory if the first argument is a directory.
0
 
LVL 11

Expert Comment

by:avizit
Comment Utility
if test -d $1  

to check if first parameter is directory
0
 
LVL 11

Expert Comment

by:avizit
Comment Utility
remove the "test" .. anyway  lemmec posted the correct answer
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:seremaz
Comment Utility
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
Comment Utility
Use nested ifs. Is this homework?
0
 

Author Comment

by:seremaz
Comment Utility
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
Comment Utility
You are welcome. But is a 'B' grading justified?
0
 

Author Comment

by:seremaz
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now