Sponsored Content
Top Forums Shell Programming and Scripting test with two conditions (OR) Post 302262891 by chebarbudo on Saturday 29th of November 2008 01:25:15 PM
Old 11-29-2008
Question test with two conditions (OR)

Hi there,
I'm very surprised that I can't find this myself and I'm sorry to bother you with such a stupid question. I just want to write a test with one condition or another one. I want either the first argument to be equal to 'this' or the second argument to be equal to 'that'.
Code:
~$ cat test
(( $1='this' || $2='that' )) && echo test1 says ok
(( $1=='this' || $2=='that' )) && echo test2 says ok
[[ $1='this' || $2='that' ]] && echo test3 says ok
[[ $1=='this' || $2=='that' ]] && echo test4 says ok
~$ test wrong wrong
test: line 1: ((: wrong=this || wrong=that : attempted assignment to non-variable (error token is "=that ")
test2 says ok
test3 says ok
test4 says ok
~$ test this wrong
test: line 1: ((: this=this || wrong=that : attempted assignment to non-variable (error token is "=that ")
test2 says ok
test3 says ok
test4 says ok
~$ test wrong that
test: line 1: ((: wrong=this || that=that : attempted assignment to non-variable (error token is "=that ")
test2 says ok
test3 says ok
test4 says ok
~$ test this that
test: line 1: ((: this=this || that=that : attempted assignment to non-variable (error token is "=that ")
test2 says ok
test3 says ok
test4 says ok

To sum up those tests, first construct will never work, and other constructs will always return true.
Can you help me with that, I can't believe this can be hard!
Thanks in advance
Santiago
 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

2. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

3. Shell Programming and Scripting

Prefixing test case methods with letter 'test'

Hi, I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Discussion started by: royalibrahim
5 Replies

4. Shell Programming and Scripting

Errors in if conditions with to many OR conditions

Hi ALL I have a script where in i need to check for several values in if conditons but when i execute the script it throws error such as "TOO MANY ARGUMENTS" if then msg="BM VAR Issue :: bmaRequestVAR=$bmaRequestVAR , nltBMVAR=$nltBMVAR , bmaResponseVAR=$bmaResponseVAR ,... (10 Replies)
Discussion started by: nikhil jain
10 Replies

5. Shell Programming and Scripting

Shc : trying to test functionality "test" compiling but can not execute

I am testing shc to see if it would help with my need. Im at a point where Im trying to compile and test the "test.ksh" file that comes in the tar ball : shc-3.8.9> shc -v -r -f test.ksh shc shll=ksh shc =-c shc =exec '%s' "$@" shc = shc opts= shc: cc test.ksh.x.c -o test.ksh.x... (7 Replies)
Discussion started by: popeye
7 Replies

6. Shell Programming and Scripting

Shell test conditions

Are these shell test conditions in any man pages? I do not see them in bash or ksh man pages. The tests below are test conditions provided by the shell: -b file = True if the file exists and is block special file. -c file = True if the file exists and is character special file. -d file... (3 Replies)
Discussion started by: cokedude
3 Replies
tag(3tcl)                                                                                                                                tag(3tcl)

NAME
tag - Manipulate tagged files SYNOPSIS
tag option ?arg arg ...? DESCRIPTION
The tag procedure provides a number of options for manipulating tagged files. COMMANDS
tag readfile filename Reads the file with the given filename and returns a list where each list element is a tag record, which is represented by a list of label-value pairs, or label-value-endlabel triples. The tag header is the first element returned. tag writefile filename list Takes a list in the format used internally in tcl programs for tagged data and writes it as a tagged file. tag extract list tests Takes a list in tagged format, and a list of conditions, and returns a new list in tagged format which contains those tag records which match the conditions. The tests is a list of test items, each of which is a list of the form { labelname condition matchvalue } The conditions are == String equals != String not equal <= Less than or equal -in Is the test value a member of the list given as the matchvalue -contains Does the match value contain the test value as a case insensitive substring. -earlier Date earlier -later Date later - dates are in ISO format (yyyy-mm-dd [hh:mm:ss]). -exists Does the label exist in this record. BUGS
tag readfile reads the whole file into memory before turning it into a list. Should be more memory efficient. The -earlier and -later comparisons require TCL8.3 AUTHOR
John Lines (john@paladin.demon.co.uk) July 3, 2000 tag(3tcl)
All times are GMT -4. The time now is 09:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy