Avatar of beer9
beer9Flag for India

asked on 

Difference of (( )) and $(( )) in bash script

Hello, While going through reading some bash tutorial I am stuck here..

(( )) Evaluates and assigns value to a variable and does math in a shell
$(( )) Evaluates the enclosed expression

Open in new window


I am not able to get where should I use (( )) and $(( )). Could someone please provide me an example to understand it better. Thanks!
Shell Scripting

Avatar of undefined
Last Comment
simon3270
ASKER CERTIFIED SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of farzanj
farzanj
Flag of Canada image

$(( )) is for mathematical evaluation (finding a value)
(( )) is for logical expression (true or false conditions)
Avatar of farzanj
farzanj
Flag of Canada image

(( )) is for mathematical logical conditions
(( 7+8 == 15 )) && echo true

[[ ]] is for non mathematical logic
name=beer9
[[ $name == "beer9" ]] && echo equal
SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Shell Scripting
Shell Scripting

The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.

11K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo