[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ksh scripting-difference between { and (

Posted on 2005-04-11
4
Medium Priority
?
281 Views
Last Modified: 2013-12-27
i asked a question earlier and was given a great solution and here is the command:
status=$(egrep -c -i 'fail' /home/mtsadmin/GABS_trades_EUR_bcp.out)

now i want to understand the use of paranthesis vs squiggly brackets '{}'?
and what is the $ doing in this case?

thanks to all
0
Comment
Question by:pdadddino
  • 2
4 Comments
 

Author Comment

by:pdadddino
ID: 13757496
if (($status == 0))

same for this command. what do double parenthesis mean?
0
 
LVL 1

Accepted Solution

by:
kusuma_hs earned 1000 total points
ID: 13760025
Hi,

(( .. )) are used in arithmetic expressions;
and
( .. ) are used to create subshells.

 ( list )
              Execute list in a subshell.  There is no implicit way to pass environment changes from  a  subshell
              back to its parent.

 { list }
              Compound construct; list is executed, but not in a subshell.  Note that { and } are reserved words,
              not meta-characters.

Please go through man ksh for more info..

Regards,
Kusuma
0
 
LVL 10

Assisted Solution

by:neteducation
neteducation earned 1000 total points
ID: 13760127
xx=$(somecommand)
means that somecommand is executed and the output of that command is assigned to a variable called xx
this is korn shell syntax. maybe you know the bourne shell syntax
xx=`somecommand`
which does exactly the same and is also valid for kornshell.

as for the {} let me do an example
flower=rose
echo $flowers
does not give you any output while
echo ${flower}s
gives you "roses" as output (echo $flower s would give you "rose s" which you would probably not want)

finally the (( )), as described by kusuma are use to tell the korn shell that we are in aritmetics. This is often used for if-statements. let's make an example:

$ if (( 2+2 == 4 ))
> then
> echo hello
> fi
hello

$ if [[ 2+2 == 4 ]]
> then
> echo hallo
> fi

In the first example the condition is true, because we are in aritmethics. In the second example (square brackets) we are talking about text, which means the string "2+2" is compared to the string "4" which of course is not the same.

0
 

Author Comment

by:pdadddino
ID: 13765412
Thanks for taking the time. It certainly clears some things up!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month20 days, left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question