Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 28 Jul 2014, 02:31
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
bash script
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [4 Posts]  
Author Message
emily22

Joined: 06 May 2012
Posts: 3

PostPosted: Sun 06 May 2012, 05:06    Post subject:  bash script
Subject description: variables assignment
 

hey there to all!

I'm writing a bash script and I wonder what is the correct syntax for arithmetic expression when it comes to integers which are stored in variables.

For example

aa=23
bbb=35
cccc=479

and I want to assign:

dd=$(($aa+$bbb))

or

aa=$(($aa+$bbb))

or

ee=$(($cccc-$aa))

Is this correct or let is working better?
Also do I have to leave white spaces between operands?
Back to top
View user's profile Send private message 
zigbert


Joined: 29 Mar 2006
Posts: 5647
Location: Valåmoen, Norway

PostPosted: Sun 06 May 2012, 06:31    Post subject:  

Why not test?
Code:
# aa=23; bbb=35; dd=$(($aa+$bbb)); echo $dd
58
Correct!
_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
emily22

Joined: 06 May 2012
Posts: 3

PostPosted: Sun 06 May 2012, 07:20    Post subject:  

zigbert wrote:
Why not test?
Code:
# aa=23; bbb=35; dd=$(($aa+$bbb)); echo $dd
58
Correct!


yes you're right I just wanted to know if both formats are acceptable
and which one is more preferable!
Back to top
View user's profile Send private message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 508

PostPosted: Tue 08 May 2012, 10:57    Post subject:  

emily22 wrote:
zigbert wrote:
Why not test?
Code:
# aa=23; bbb=35; dd=$(($aa+$bbb)); echo $dd
58
Correct!


yes you're right I just wanted to know if both formats are acceptable
and which one is more preferable!


In general, I like to leave white spaces because it makes the expression easier to read. It doesn't seem to have any impact on speed.

I also use the ${AA} form of the variable use even in cases where it is not needed if it makes the expression clearer.

When coding something biggish, I try to use names that make sense for what I am doing. Even though using $KBYTES takes more characters than $N, it is worth doing on something you have to maintain.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [4 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0467s ][ Queries: 11 (0.0045s) ][ GZIP on ]