![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help me in sending parameters from sqlplus script to unix shell script | Hara | Shell Programming and Scripting | 2 | 01-29-2008 12:31 PM |
| Shell Script: want to insert values in database when update script runs | ring | Shell Programming and Scripting | 1 | 10-25-2007 12:06 AM |
| here document to automate perl script that call script | hogger84 | Shell Programming and Scripting | 3 | 10-22-2007 07:15 AM |
| returning to the parent shell after invoking a script within a script | gurukottur | Shell Programming and Scripting | 5 | 09-26-2006 04:05 AM |
| return valuse from child script to parent script | borncrazy | Shell Programming and Scripting | 1 | 08-20-2004 12:39 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
aix script
hi all,
do yo know what is double "[[" and "]]" means? Here's an example: [[ -z $ERROROUTPUT ]] || echo "$TITLE" thanks, itik |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
IT's a synonym for test, it returns true or false.
That code fragment means: test if $ERROROUTPUT is zero length || echo "$TITLE" It doesn't make much sense in a programming context because the || allows the echo part to run regardless - it is a boolean or i.e., the echo happens whether the first test evaluates true or false... |
|
#3
|
|||
|
|||
|
Quote:
...testing if .bash_history is a file: Quote:
/L |
|
#4
|
|||
|
|||
|
The form "[ ]" is essentially calling the external "test" command, and thus everything is evaluated by the shell first. That's why you get "test: argument expected" when an unquoted variable is NULL, since the expression evaluates to "[ -z ]".
When using "[ ]", you really need to quote all values/variables. But, with the double-brackets, the test is a shell builtin. So nothing needs to be quoted, since it is not evaluated prior to being tested. Plus, you will save dozens of milliseconds by avoiding an external program. Using the double-bracket with && is my favorite way of doing a simple if/then: Code:
[[ 1 == 1 ]] && echo "equal" || echo "not equal" Code:
if [[ 1 == 1 ]]; then
echo "equal"
else
echo "not equal"
fi
Code:
[[ 1 == 1 ]] && ehco "equal" || echo "not equal" You can also do compounding: Code:
[[ 1 == 1 ]] && { echo "equal"; date; } || echo "not equal"
Note that the amperstand can be used after any ordinary command: Code:
grep -q localhost /etc/hosts && echo "found" || echo "not found" Last edited by gus2000; 11-09-2007 at 12:24 PM. |
|
#5
|
|||
|
|||
|
Thanks a bunch for the explanation!
Now I can save hundreds of milliseconds in my scripts I had some idea that the quoting rules were different, but wasn't clear about exactly what it meant in practical use. And man bash isn't very helpful, or just too much text for me... /Lakris |
|
#6
|
|||
|
|||
|
That can amount to an awful lot of time if you do it inside a deeply-nested loop. Suppose you execute the loop surrounding it 100.000 times: 100ms times 100.000 are 10.000 seconds, which are ~3 hours - not bad, yes?
bakunin |
|||
| Google The UNIX and Linux Forums |