Can someone please explain the code snippet above?
The trap command bit is fine but [[ $mode = "INTERACTIVE" ]] && is the hazy part.
Generally we use an if before [[ ]], but it is not being used here!
I was also experimenting with the below code snippet and it seemed to work fine as long as I was not putting #! /usr/bin/ksh at the top of the script.
Code:
[[ `ps -ef | grep Hawkmoon | grep -v grep` ]]
Why is it that it is running sans #! /usr/bin/ksh only?
I am using Solaris 5.8 by the way.
Thanks in advance .
Last edited by King Nothing; 10-07-2009 at 02:16 PM..
[[ expression ]]
Evaluates expression and returns a zero exit status when expression is true.
See Conditional Expressions below, for a description of expression.
Code:
expression1 && expression2
True, if expression1 and expression2 are both true.
The && construct makes use of the fact that in order to find out whether both expressions are true, first the left side gets evaluated. Because of efficiency the right side only gets evaluated if the left side is true. If the left side is false it does not matter what value the right side evaluates to, so it never gets evaluated. Thus this happens to work out like an if then construction. The end value of the && construct then never gets used. I personally prefer the if then else way of testing conditions since it usually provides cleaner, more legible code.
I don't know why the examples you provide don't work with ksh. They sure work in my ksh (does /usr/bin/ksh exist on your system?). The first example strikes me as strange because of the parentheses, which mean the trap statement is run in a separate environment, so it will never output the statements in the current environment. If you use { .. ;} instead it will work:
Hi All,
Hope you all are doing good. Yesterday in my project i came across a scenario which i can not guess why it was working in one region and why it was not in another region. Please find my issue below.
I am using AIX version 6.0 of UNIX in my project, in shell scripting i have the... (1 Reply)
I wanted to store the number inside the square bracket between colon( : ) and closing suqre bracket(]) in some variable.
Suppose I have lines like :
Input file :
20140320 00:08:23.846 INFO 84] - anything in line
20140320 00:08:23.846 Test 589] - Virtual and lab lab anything... (18 Replies)
I wanted to compare the value inside the Squre bracket after Colon ( : ) based on any value(seperated by or operator | ) inside the variable Thread and if match found then wnated to store in output file
Input file :
20140320 00:08:43.918 INO 35] - Corporate hub is
20140320 00:08:43.918... (2 Replies)
Hi frieds, I don't understand the difference between single square bracket and double square brackets in a IF condition.
Ex.
if ;
then
RETURNJOB=1
else
RETURNJOB=0
fi
It run, but this
if ];
then
RETURNJOB=1
else
RETURNJOB=0
fi (4 Replies)
Hi All,
I have a text file which looks like this:
computer programming
systems engineering
I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this:
computer programming
systems engineering
I am using... (3 Replies)
hi guys,
i'm writing a script that looks for a unquie id in a file and replaces a string between two square brackets on the same line as the unquie id:
.......
.......
0001 zz 43242 replace this text] name
0002 sd 65466 UK] country
.......
.......
how can i find line with id 0001... (6 Replies)
Hi
First apologies if this has been raised before.
I've got the following in a ksh script:
if ]
For some reason this does not work. But if I remove the double square brackets to:
if
This works.
I thought ksh supported the ]. Or is there more to it?
Thanks in advance. (3 Replies)
One of the senior administrators gave me a shell script to modify and it begins as follows:
if ] && ]
{more code follows}
Why the double square brackets? (10 Replies)