LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2012, 01:43 PM   #1
johnifanx98
LQ Newbie
 
Registered: Jan 2008
Posts: 26

Rep: Reputation: 0
Why need double braces to evaluate a math operation?


like
Code:
echo $(($1*$2))
I know
Code:
echo $($1*$2)
not work...
 
Old 02-24-2012, 02:05 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Because the $(...) syntax is for command substitution and bash cannot distinguish them otherwise.
 
Old 02-24-2012, 02:23 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,508

Rep: Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102Reputation: 2102
$((op)) tells it to do a math operation
$(op) tells it to execute that command as if it was typed on the command line, ie: $(date +%s)
 
Old 02-24-2012, 10:20 PM   #4
johnifanx98
LQ Newbie
 
Registered: Jan 2008
Posts: 26

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by suicidaleggroll View Post
$((op)) tells it to do a math operation
$(op) tells it to execute that command as if it was typed on the command line, ie: $(date +%s)
I like this one. Is there a manual to check this, like "help [["?
 
Old 02-24-2012, 10:33 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,516

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
Try checking out man bash
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C (math.h)not doing right math? exp() issue. knockout_artist Programming 7 11-25-2011 02:13 PM
missing braces around initializer tz_uw Linux - Newbie 4 09-05-2011 01:14 AM
[SOLVED] Shell script braces and variables Woodsman Programming 5 08-13-2010 09:39 PM
GCC giving warning - braces around initializers fcdev Programming 4 09-28-2007 01:21 AM
math program that I can enter math functions ... Four General 5 04-19-2006 08:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration