08-21-2009
Mine and franklin52 solutions look similar but are actually very different.
franklin52 is using a "regular expression" - see "man 5 regexp" (and "man" for your shell) within a sub-shell (enclosed by parentheses) and testing the success or failure with the "&&" operative before using a "test" for the right hand side of the and.
I am just using a "test" - see "man 1 test" (and "man" for your shell) with parentheses overriding the default execution order of the ands and ors. Similar to a mathematical function. The parentheses are escaped so they will be passed to "test" rather than being actioned by the shell.
Thus the use of parentheses is totally different syntax, but the use of single square brackets to enclose a condition is similar.
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi Guys,
I want to use if conition for my script. Before I used it tried it with some small test scripts. But it was not succeeded. My script and screen output as follows,
Script:
echo 'Do you think Yes or No (y/n) : '
read ans
echo You input anser as $ans
ans1=y
if ( $ans == $ans1... (5 Replies)
Discussion started by: maheshsri
5 Replies
2. Shell Programming and Scripting
hi, :)
pls consider the following if statement
if //g') ]
then
........
else
.......
when i execute the script i am getting the following error
'(' unexpected
I am not able to find the mistake.
could anybody tell where i did mistake.
cheers
RRK (13 Replies)
Discussion started by: ravi raj kumar
13 Replies
3. Shell Programming and Scripting
hi,
actully i need the belp for the below.
host_list=" Host1 host2 host3 host4 "
n=`hostname`
i need to put the condition like the below
if n is among the host mention in the host_list if
then
#some stugg
else
# some other stuff
fi (1 Reply)
Discussion started by: mail2sant
1 Replies
4. Shell Programming and Scripting
Hi ,
I am trying the following simple script . But it is always giving 1 output. Dont know why
#!/bin/sh
find . -name "a.log"
if ; then
echo "1"
else
echo "0"
fi
Kindly advice. it is giving 1 output even when the a.log file is not there (26 Replies)
Discussion started by: himvat
26 Replies
5. Shell Programming and Scripting
Hi all,
I have task to delete two different files from all file system. one is core file & other is old file.
i can delete core file but for old file i have to mv in different location.
i wrote a script but it is not working.
i have a two variables in this script first one is delcnt &... (6 Replies)
Discussion started by: dravi_laxmi
6 Replies
6. Shell Programming and Scripting
Hi,
I need to use if condition for search a file pattern on a particular location.
cd $file_Path
if ||
then
do this
else
do that
fi
Can someone help me with the if part, how i can put those conditions?
make sure format should be *.file* and *.file
file is a keyword which i... (5 Replies)
Discussion started by: amit.mathur08
5 Replies
7. Shell Programming and Scripting
Hi i am writing a script where i am running , 5 scripts together in 1 script .
Now what i want is when these 5 scripts run completely , i should execute some other commands like i have compile the data etc.
I have have 5 echo statements at the end of all those scripts .
Like echo "1 is done" in... (1 Reply)
Discussion started by: honey26
1 Replies
8. Shell Programming and Scripting
Hi All,
I am using below if condition to check whether null is passed as a parameter to the program
if or ;
then
echo "ABC">>$FILE
else
echo "CDF">>$FILE
fi
However it is saying me null=null command not found . Please help me with this (9 Replies)
Discussion started by: Hypesslearner
9 Replies
9. Shell Programming and Scripting
Hi All,
Seeking for your assistance on how to condition it correctly.
cat file1.txt
290,1663,43,888,0,0.00,86.91,0.00,26.98,0.00
290,1663,52,0,0,0.00,0.00,0.00,0.00,0.00
290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00
1st scenario:
if the fourth column contains 888s and 0s it is by... (16 Replies)
Discussion started by: znesotomayor
16 Replies
for(n) Tcl Built-In Commands for(n)
__________________________________________________________________________________________________________________________________________________
NAME
for - ``For'' loop
SYNOPSIS
for start test next body
_________________________________________________________________
DESCRIPTION
For is a looping command, similar in structure to the C for statement. The start, next, and body arguments must be Tcl command strings,
and test is an expression string. The for command first invokes the Tcl interpreter to execute start. Then it repeatedly evaluates test
as an expression; if the result is non-zero it invokes the Tcl interpreter on body, then invokes the Tcl interpreter on next, then repeats
the loop. The command terminates when test evaluates to 0. If a continue command is invoked within body then any remaining commands in
the current execution of body are skipped; processing continues by invoking the Tcl interpreter on next, then evaluating test, and so on.
If a break command is invoked within body or next, then the for command will return immediately. The operation of break and continue are
similar to the corresponding statements in C. For returns an empty string.
Note: test should almost always be enclosed in braces. If not, variable substitutions will be made before the for command starts execut-
ing, which means that variable changes made by the loop body will not be considered in the expression. This is likely to result in an
infinite loop. If test is enclosed in braces, variable substitutions are delayed until the expression is evaluated (before each loop iter-
ation), so changes in the variables will be visible. For an example, try the following script with and without the braces around $x<10:
for {set x 0} {$x<10} {incr x} {
puts "x is $x"
}
SEE ALSO
break, continue, foreach, while
KEYWORDS
for, iteration, looping
Tcl for(n)