i am wondering if someone can give me a clear explanation of the differneces between parentheses and brackets, both single and double.
i have heard that double parentheses (( are used for numerical expressions and that single brackets [ are used for strings. but i see very different behavior on this forum and elsewhere. i would love some clarity!
[[ and [ are shell builtins (in modern shells)
for test. test or [[ - you have to complete them with ]] - are use either in if statments or in combined statements
the -eq -gt -lt -ge -le comparisons are for comaring integer numbers in [[ ]]
comparing strings- [[ "$string1" = "$string2" ]]
There are other modern operators for testing file times: for example -ot -nt
See the ksh man page
$(( )) does arithmetic operations - whole numbers (long integers).
allowed operators are + - * / and some others like %.
$(( 3 + 1 )) evaluates a 4
$( some command[s] ) runs one or more commands in background
it works just like the backticks: `command`
read all of a file into an envrionment variable
myvar=$(< somefile)
put the date in a variable
myvar=$( date )
Hi Froum.
I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is.
I have the following data:
Before:
... (32 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.could you explain me what are the rules when we are using double parentesis in if statement,if I put ,the code is working ,with (( is not
#!/bin/bash
if (($# > 0))
then
if ((! -d "$1"))
then
echo "Directory $1 not found"
fi
else
echo Problem
fi (8 Replies)
Hello,
I have done a great deal of research on this and still cannot come to an understanding of the following:
In if-else statements in shell scripting I have seen examples of single brackets, double brackets, single parantheses, and double paratheses. When should each one be used?
And... (2 Replies)
Hi,
I just came across an interesting shell script syntax like the one below:
] && (trap 'rm -rf ${WORK_DIR}/*.$$; echo "\n\nInterrupted !!\n\n"; exit 4' 1 2 3 15)
Can someone please explain the code snippet above?
The trap command bit is fine but ] && is the hazy part.
Generally we use an... (2 Replies)
Dear All,
Recently got some sample from internet search for array handle in shell script, and I can not understand why we need to put double brackets when extracting array values by this way :
for ((i=0; i<${#admins}; i++)); do
echo "${admins}"
done
if modify from double to single... (2 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)
i m trying the following command but its not working:
sed 's/find/\'replace\'/g' myFile
but the sed enters into new line
# sed 's/find/re\'place/g' myFile
>
I havn't any idea how to put single quote in my replace string. Your early help woud be appreciated. Thanx (2 Replies)