checking for number of arguments.

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions checking for number of arguments.
# 1  
Old 04-23-2010
checking for number of arguments.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
Your script must check for the correct number of arguments (one argument). If somebody tries to invoke the script without passing in the correct number of arguments, then output this usage message: Usage: assignment4.sh <directory_name>



2. Relevant commands, code, scripts, algorithms:

I know it should be an if statement of some sort.

3. The attempts at a solution (include all code and scripts):

I have this written to check to see if the file is a directory or not, does this also check for the number of arguments?

file=$1

if [ ! -d $file ]
then
echo "$file: is not a directory"
fi
exit


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Florida State, Myers, COP3353

COP 3353

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 04-23-2010
It does not check the number of arguments. Follow the steps, there's nothing that rejects or checks it, and the shell doesn't examine your script to do that for you.

The number of arguments is available as a special variable "$#".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If number of arguments =$ or $

Hi, I am having a bit of trouble writing this. I have the script working if I only use 1 of these but it's not working the way i need it to. Basically more above the script i may or may not have a 5th variable defined. if i do it does a process before getting to the rest of the script.... (2 Replies)
Discussion started by: techy1
2 Replies

2. Shell Programming and Scripting

Number of arguments to array - Perl Script

I have the following proc. proc get_add {arg1 arg2 arg3 arg4 arg 5 .. ... arg N } { } i need to count the number of arguments and also i need those arguments stored in an array. please help out ---------- Post updated at 06:33 PM ---------- Previous update was at 05:30 PM ---------- ... (1 Reply)
Discussion started by: Syed Imran
1 Replies

3. Programming

Checking which arguments are supplied

I have written this C++ program and I am using getopt_long and want to chech when the user supplies the arguments so that I can put a default or otherwise. Currently I am using hasargv or Pc.get_string("key",s), Pc.get_real("key",s), etc to detect whether the user supplied a value. For... (3 Replies)
Discussion started by: kristinu
3 Replies

4. Programming

Checking which arguments are supplied

I have written this C++ program and I am using getopt_long (2 Replies)
Discussion started by: kristinu
2 Replies

5. Programming

Checking which arguments are supplied

I have written this C++ program and I am using getopt_long and (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

checking a number

ok im trying to find out how many cars a user enters. Its giving me an error message of "integer expression expected" Basically if i enter any number over 0 (zero) it should continue read -p "How many cars:" carsn test $cars -ge 1 test $? -ne 0 && read -p "Invalid number.... (8 Replies)
Discussion started by: gangsta
8 Replies

7. Shell Programming and Scripting

[C SHELL] How to pass dynamic number of arguments

I have a task. The scenario is like this. I have a operation program (OPR1) , whose function is to simply double the (single)value it receives as input. I have to write a script to operate the OPR1 and save its output in a file. Later, I have to modify the script so as to be able to operate ... (0 Replies)
Discussion started by: animesharma
0 Replies

8. Shell Programming and Scripting

Checking arguments

I shoe here the start of a csh script I have written. I am trying to write some code to check the arguments and if the arguments don't match the tags, I will abort and display an error. For example using ./script.csh -r=10/20.30/40 -xyz=2/3/4 will give an error as the -xyz tag doea not... (24 Replies)
Discussion started by: kristinu
24 Replies

9. UNIX for Dummies Questions & Answers

maximum number of arguments

Hi, What is the maximum number of arguments that could be passed to zsh ? To find out that I tried a simple script. And the maximum number of arguments that could be passed turned out to be 23394 #! /bin/zsh arg=1 i=1 subIndex=23000 while do arg=$arg" "$i i=$(($i + 1))... (9 Replies)
Discussion started by: matrixmadhan
9 Replies

10. Shell Programming and Scripting

read number of arguments in c shell

I am writing script in c shell and using this script to read the command line arguments, but it is not working. Pl. someone let me know what is the problem. #!/bin/csh -f if ($#argv <> 2) then echo "you must give exactly two parameters" else set name1 = $argv ... (1 Reply)
Discussion started by: skumar11
1 Replies
Login or Register to Ask a Question