Bash script variables assignment syntax question
Bash script variables assignment syntax question
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?
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?
Hi emily22; "Let" is kinda diminished, or depreciated as it were ( not used ).
I can`t remember the forum name of the competent member that showed me this:
I can`t remember the forum name of the competent member that showed me this:
Code: Select all
aa=23 ; bbb=35
((dd=$aa+$bbb))
echo $dd
works, but what's wrong with dd=$(($aa + $bbb)) ?sunburnt wrote:Hi emily22; "Let" is kinda diminished, or depreciated as it were ( not used ).
I can`t remember the forum name of the competent member that showed me this:Code: Select all
aa=23 ; bbb=35 ((dd=$aa+$bbb)) echo $dd
Hello.
Even if the "let" statements are officially deprecated, the following script does not work if the "let" statements are removed.
Is it me, bash (version 4.1.0-1_i686, 2009), my computer, my Puppy version (lupu 5.25 retro4), my attitude towards life, a spell from my ex? Someone has an explanation? Thanks in advance.
Also, before you ask, I have found a reason to open 4 console windows at the same time!
BFN.
Even if the "let" statements are officially deprecated, the following script does not work if the "let" statements are removed.
Code: Select all
#!/bin/sh
# ~/$MAPPS/bin/urxvt-fordo-cascade-4.sh
####
# Ce script-ci doit demeurer en l'état.
# (c) Christian L'Écuyer, Gatineau (Qc), Canada, janvier 2012. Gratuiciel, mais tous droits réservés.
# Courriel : http://scr.im/reyucelc
#
# Si ça ne marche pas, assurez-vous qu'un autre "rxvt" ne tourne pas quelque part en mémoire.
####
if [ "`pidof rxvt`" != "" ];then
for i in `seq 4`;
do
wmctrl -c Console
done
exit
else
export gm="g 80x16"
let x=45
let y=80
for i in `seq 4`;
do
rxvt -bd grey10 -b 4 -fg white -cr green -sr +st +tcw -bc -tint black -sh 57 -T "Console $i" -$gm-$x-$y &
let x=$x+120
let y=$y+170
sleep 0.17s
done
fi
Also, before you ask, I have found a reason to open 4 console windows at the same time!
BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
musher0;
Code: Select all
x=45 ; y=80
........
((x=$x+120)) ; ((y=$y+170))
emily22 wrote:For example
aa=23
bbb=35
cccc=479
and I want to assign:
dd=$(($aa+$bbb))
Code: Select all
#!/bin/bash
aa=23
bbb=35
cccc=479
let dd=aa+bbb
echo -e "\ndd= $dd\n"
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
see amigo's post for portable, alternative syntaxmusher0 wrote:Hello.
Even if the "let" statements are officially deprecated, the following script does not work if the "let" statements are removed.
...
Is it me, bash (version 4.1.0-1_i686, 2009), my computer, my Puppy version (lupu 5.25 retro4), my attitude towards life, a spell from my ex? Someone has an explanation? Thanks in advance.
Also, before you ask, I have found a reason to open 4 console windows at the same time!
BFN.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
Inside $((....)) bash allows you to omit the $ preface to all the variables:sunburnt wrote:I can`t remember the forum name of the competent member that showed me this:Code: Select all
aa=23 ; bbb=35 ((dd=$aa+$bbb)) echo $dd
a=24 b=56 c=$((a+b)); echo $c
80