If number of arguments =$ or $


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If number of arguments =$ or $
# 1  
Old 07-04-2013
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. if there is not a 5th variable it skips that if statement and moves on.

Now the problem I am having is I need to have a check to make sure that the person using the script has 4 or 5 variables defined depending on which part of the script they are using.

When it checks how many variables it has it keeps complaining about this part:

Code:
        if [[ $# -ne 4 ]] || [[ $# -ne 5 ]]
        then

for some reason if there is a 5th variable the script is only trying to find 4 not or 4 or 5.

Can someone correct me here? I tried a few things and nothing seemed to do the trick.
# 2  
Old 07-04-2013
Quote:
Originally Posted by techy1
Code:
        if [[ $# -ne 4 ]] || [[ $# -ne 5 ]]
        then

The conjunction of the set of integers not equal to 4 and the set of integers not equal to 5 is the set of all integers. Put another way, the expression x != 4 || x != 5 is always true. For that expression to evaluate falsely would require the existence of an integer that is simultaneously equal to 4 and equal to 5.

If the goal is for the expression to only evaluate to true when x is any value except 4 or 5, then you need to use &&.

Regards,
Alister

Last edited by alister; 07-04-2013 at 08:58 PM..
# 3  
Old 07-05-2013
Hi.

Possibly of use: http://en.wikipedia.org/wiki/De_Morgan%27s_laws ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

[BASH] Read pipe of unkown number of arguments?

Heays So i have that script to which i'd like to pipe (rather than just regular arguments) some data from another virtual output command. Simplified: echo * | script.sh When i know how many args i expect, i can handle this simple by: && \ read ONE TWO && \ set ONE TWO echo "$1 : $2... (7 Replies)
Discussion started by: sea
7 Replies

2. Shell Programming and Scripting

Case -- esac number of arguments problem

hi Scripting experts, I am using case..esac in my script .. I have given 6 option..e.g. 1 2 3 4 5 and *, howerver my script works welll for 1st 4 options but for 5 it considers * and exists. Is there a maximum limit on number of options given for case ..esac? (1 Reply)
Discussion started by: sdgawande
1 Replies

3. Shell Programming and Scripting

Incorrect number of command line arguments and missing required files

I am developing a script. This script takes in one parameter which is the name of a file whose content is a list of names of some files. The script can check whether those files exist in current directory. Here is my question: If the number of provided parameters is less than one or one of the... (2 Replies)
Discussion started by: Ray Sun
2 Replies

4. 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

5. Shell Programming and Scripting

How to pass different number of arguments in a single shot

I have one configuration file. The number of lines in the file will vary. I need to pass each line as a parameter to a shell script in a single shot. Ex: Suppose file contains: ou=x,o=z o=y Suppose the shell script name is sample.sh. Then the script should be called like sample.sh ou=x.o=z... (6 Replies)
Discussion started by: saurabhkoar
6 Replies

6. 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

7. Shell Programming and Scripting

Need help with examine the number files in directories given as arguments

Hi , this is homework .. I have to finish it tomorrow, I did my best , but I found it so difficult .. Can You HELP Me ??! Write a bash shell script filestatic. The script should examine the number files in directories given as arguments (parameters) to this script. a. if one argument is... (1 Reply)
Discussion started by: abo-el-sos
1 Replies

8. Homework & Coursework Questions

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... (1 Reply)
Discussion started by: brooksie91
1 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