Sponsored Content
Top Forums Shell Programming and Scripting difference in the two test operators Post 302587794 by zulfi123786 on Friday 6th of January 2012 02:56:57 AM
Old 01-06-2012
difference in the two test operators

could any one please help me understand the difference between double square bracket test operator and single square bracket test operator.

I have seen one difference with the below code but not sure which one has to be used and when:

Code:
 
unix79:z54402:/data/ds/scripts $ cat > T
one,,two
unix79:z54402:/data/ds/scripts $ z=`cat T|cut -d, -f2,2`
unix79:z54402:/data/ds/scripts $ if [[ -z $z ]]
> then echo success
> else echo fail
> fi
success
unix79:z54402:/data/ds/scripts $ if [ -z $z ]
> then echo success
> else echo fail
>  fi
ksh: test: 0403-004 Specify a parameter with this command.
fail
unix79:z54402:/data/ds/scripts $

 

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

If with set operators

Hi guys, I'm trying to run more than one "if" condition at once. What I want is something like if ] or ] or ]; then ... I can't remember the syntax for using this or/and set operators. Can someone please assist/ jog my memory? thanks Khoom (2 Replies)
Discussion started by: Khoomfire
2 Replies

2. UNIX for Dummies Questions & Answers

Operators

I am trying to understand Does the following: {tmp+=$10} Mean take $10 and add them all up and call it tmp thanks! (2 Replies)
Discussion started by: llsmr777
2 Replies

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

4. Shell Programming and Scripting

And and OR Operators with If Statement.

Hi All, I have 2 variables. Result1 and Result2. I want to put a condition that if Both are True then echo "All True" Else Show Error. Right now i am doing this and getting error. if ; then echo "All True" else echo "Failed" fi; Error. line 8: ' Solution: Looking for (2 Replies)
Discussion started by: mkashif
2 Replies

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

6. Shell Programming and Scripting

Operators

I really don't know the meaning of these operators. Could someone explain the meanings so I can make my test for today? <, <=, ==, !=, >=, >, ||, &&, ! ~ , !~ Thanks! (1 Reply)
Discussion started by: Erjen
1 Replies

7. Homework & Coursework Questions

Operators

I really don't know the meaning of these operators. Could someone explain the meanings? <, <=, ==, !=, >=, >, ||, &&, ! ~ , !~ Thanks! (1 Reply)
Discussion started by: Erjen
1 Replies

8. UNIX for Beginners Questions & Answers

Bash -o -v -R operators

I do not know the use of the -o -v -R operators. This is what the info says and I am confused of what optname and varname mean, are they just normal variable? -o optname True if the shell option optname is enabled. See the list of options under the ... (6 Replies)
Discussion started by: kristinu
6 Replies
BBCOMBOTEST.CFG(5)						File Formats Manual						BBCOMBOTEST.CFG(5)

NAME
bbcombotest.cfg - Configuration of bbcombotest tool SYNOPSIS
$BBHOME/etc/bbcombotest.cfg DESCRIPTION
bbcombotest(1) uses it's own configuration file, $BBHOME/etc/bbcombotest.cfg Each line in this file defines a combined test. FILE FORMAT
Each line of the file defines a new combined test. Blank lines and lines starting with a hash mark (#) are treated as comments and ignored. The configuration file uses the hostnames and testnames that are already used in your Xymon bb-hosts file. These are then combined using normal logical operators - "||" for "or", "&&" for "and" etc. A simple test - e.g. "Web1.http" - results in the value "1" if the "http" test for server "Web1" is green, yellow or clear. It yields the value "0" if it is red, purple or blue. Apart from the logical operations, you can also do integer arithmetic and comparisons. E.g. the following is valid: WebCluster.http = (Web1.http + Web2.http + Web3.http) >= 2 This test is green if two or more of the http tests for Web1, Web2 and Web3 are green. The full range of operators are: + Add - Subtract * Multiply / Divide % Modulo | Bit-wise "or" & Bit-wise "and" || Logical "or" && Logical "and" > Greater than < Less than >= Greater than or equal <= Less than or equal == Equal There is currently no support for a "not" operator. If you need it, use the transcription "(host.test == 0)" instead of "!host.test". NB: All operators have EQUAL PRECEDENCE. If you need something evaluated in a specific order, use parentheses to group the expressions together. If the expression comes out as "0", the combined test goes red. If it comes out as non-zero, the combined test is green. Note: If the expression involves hostnames with a character that is also an operator - e.g. if you have a host "t1-router-newyork.foo.com" with a dash in the hostname - then the operator-character must be escaped with a backslash '' in the expression, or it will be interpreted as an operator. E.g. like this: nyc.conn = (t1-router-nyc.conn || backup-router-nyc.conn) EXAMPLE
WebCluster.http = (Web1.http || Web2.http) AppSrvCluster.procs = (AppSrv1.conn && AppSrv1.procs) || (AppSrv2.conn && AppSrv2.procs) Customer.cluster = WebCluster.http && AppSrvCluster.procs The first line defines a new test, with hostname "WebCluster" and the columnname "http". It will be green if the http test on either the "Web1" or the "Web2" server is green. The second line defines a "procs" test for the "AppSrvCluster" host. Each of the AppSrv1 and AppSrv2 hosts is checked for "conn" (ping) and their "procs" test. On each host, both of these must be green, but the combined test is green if that condition is fulfilled on just one of the hosts. The third line uses the two first tests to build a "double combined" test, defining a test that shows the overall health of the system. FILES
$BBHOME/etc/bbcombotest.cfg SEE ALSO
bbcombotest(1) Xymon Version 4.2.3: 4 Feb 2009 BBCOMBOTEST.CFG(5)
All times are GMT -4. The time now is 05:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy