LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-29-2016, 12:22 PM   #1
vincix
Member
 
Registered: Feb 2011
Distribution: Centos 6.7, 7
Posts: 556

Rep: Reputation: 52
script interpreting - "let"


I'm currently reading this:
http://www.tldp.org/LDP/abs/abs-guide.pdf

What is the meaning of the following?
let "t2 = ((a = 9, 15 / 3))"
# Set "a = 9" and "t2 = 15 / 3"

I don't understand the relationship between t2 and a here. Is the answer in the comment correct?
 
Old 06-29-2016, 12:31 PM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,511

Rep: Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434
Code:
echo $a
- and -
echo $t2
will tell you the answer
 
Old 06-29-2016, 12:38 PM   #3
vincix
Member
 
Registered: Feb 2011
Distribution: Centos 6.7, 7
Posts: 556

Original Poster
Rep: Reputation: 52
Well, ok, it's correct, but that wasn't actually the question, obviously. I don't understand why this is happening.
 
Old 06-29-2016, 01:36 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,132

Rep: Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347
"a = 9" is an expression with the side effect of setting the value of variable a. It returns that value.

"," is an operator that evaluates both of its operands and returns the value of its second operand.
 
Old 06-29-2016, 01:36 PM   #5
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
You need to start reading the expression from inside the parentheses:

Code:
a = 9
Assigns 9 to a, the result of the assignment being the value assigned.
The result of
Code:
15 / 3
is 5. So, we get
Code:
let "t2 = ((9, 5))"
Now, the comma operator works like this: it discards its first operand and returns the other:
Code:
let "t2 = ((5))"
and the '5' gets assigned to t2.

Last edited by millgates; 06-29-2016 at 01:38 PM.
 
1 members found this post helpful.
Old 06-29-2016, 02:49 PM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,511

Rep: Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434
This is a quite unusual case. I mean this is not the way how it was planned to use. Especially the , (comma) operator. Which is actually uncommon/unusual.
here you can find a bit more: http://unix.stackexchange.com/questi...ash-arithmetic
 
1 members found this post helpful.
Old 06-29-2016, 03:23 PM   #7
vincix
Member
 
Registered: Feb 2011
Distribution: Centos 6.7, 7
Posts: 556

Original Poster
Rep: Reputation: 52
Quote:
Originally Posted by millgates View Post
Now, the comma operator works like this: it discards its first operand and returns the other:
Indeed, that's exactly the explanation I was looking for. But as pan64 points it, it's rather weird, at least in this case.
Thank you for the explanations and references.
 
  


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
[SOLVED] Error:: "wrong # args: should be "set varName ?newValue?" " while running TCL script rc49 Linux - Newbie 2 09-15-2016 01:01 AM
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 02:03 AM
interpreting output of "du" command? junglepunk Linux - Newbie 11 06-24-2010 05:22 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM
Interpreting "sar -n DEV" output rfrancis Red Hat 0 01-07-2005 12:42 PM


All times are GMT -5. The time now is 01:18 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