LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 02: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, 03: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, 03:23 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,552

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
$((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, 11: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, 11:33 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,552

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
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 03:13 PM
missing braces around initializer tz_uw Linux - Newbie 4 09-05-2011 02:14 AM
[SOLVED] Shell script braces and variables Woodsman Programming 5 08-13-2010 10:39 PM
GCC giving warning - braces around initializers fcdev Programming 4 09-28-2007 02:21 AM
math program that I can enter math functions ... Four General 5 04-19-2006 09:02 PM

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

All times are GMT -5. The time now is 10:39 AM.

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