Miscellaneous operators


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Miscellaneous operators
# 1  
Old 04-16-2010
Miscellaneous operators

Hi everyone,

I read some shell script code,then I have some issue.

the following code.

Code:
let "t1 = ((5 + 3, 7 - 1, 15 - 4))"
echo "t1 = $t1"

t1=11
Here t1 is set to the result of the last operation.why?
# 2  
Old 04-16-2010
Arithmetic expressions in modern shells use the same syntax as is used in the C programming language. And in C, the value of a numeric expression using the comma operator is the value of the last subexpression, in your case 15 - 4 .
# 3  
Old 04-16-2010
it's just like
Code:
((t1=5+3))   # t1 = 8
((t1=7-1))   # t1 = 6
((t1=15-4))  # t1 = 11

If you have a "modern" shell (like bash), the "let" statement is obsolete.
# 4  
Old 04-16-2010
Quote:
Originally Posted by frans
it's just like
Code:
((t1=5+3))   # t1 = 8
((t1=7-1))   # t1 = 6
((t1=15-4))  # t1 = 11

If you have a "modern" shell (like bash), the "let" statement is obsolete.
Thanks,

I understand your meaning,I use shell of fedora 11 ,I have already tested this issue in my system,and as your result.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Combining Operators

Hey everyone, I'm really getting into learning C, but as I look at more advanced example code, I see things like if (!*variable1) blah blah blah... and variable2 ^= *(variable1++); my question is, when you have a combination of two operators, like !*. The ! means 'not' and the *... (2 Replies)
Discussion started by: Lost in Cyberia
2 Replies

2. Shell Programming and Scripting

operators in if loop

Hi all, I have a variable which is having the value like below, $ echo ${p} 8 15 22 30 $ My requirement is that the variable should return true when it contains only one number like below, $ echo ${p} 15 $ Otherwise, it should return false if it contains more than one number. I... (4 Replies)
Discussion started by: raghu.iv85
4 Replies

3. Shell Programming and Scripting

Array operators

Hi Lets say I have two arrays: VAR_1 = "File_A" "File_B" "File_C" "File_D" VAR_2 = "File_A" "File_D" Is there a simple command to get the difference of these list, i.e. VAR_1_2 = "File_B" "File_C" or do I have to write a script and loop through all elements and compare them one by one? ... (1 Reply)
Discussion started by: Wernfried
1 Replies

4. Shell Programming and Scripting

Awk miscellaneous doubts

Hi, I am having the following doubts on awk. Please clarify for me. a) What does it mean? awk '$1=$1' and how does it change if I append FS="" to the above code? b) What if I use awk -vFS="\n" (i.e) setting (input) field separator to newline char, then what will be the value of $0,... (6 Replies)
Discussion started by: royalibrahim
6 Replies

5. Homework & Coursework Questions

Operators

I really don't know the meaning of these operators. Could someone explain the meanings? <, <=, ==, !=, >=, >, ||, &&, ! ~ , !~ Thanks! (1 Reply)
Discussion started by: Erjen
1 Replies

6. Shell Programming and Scripting

Operators

I really don't know the meaning of these operators. Could someone explain the meanings so I can make my test for today? <, <=, ==, !=, >=, >, ||, &&, ! ~ , !~ Thanks! (1 Reply)
Discussion started by: Erjen
1 Replies

7. Shell Programming and Scripting

And and OR Operators with If Statement.

Hi All, I have 2 variables. Result1 and Result2. I want to put a condition that if Both are True then echo "All True" Else Show Error. Right now i am doing this and getting error. if ; then echo "All True" else echo "Failed" fi; Error. line 8: ' Solution: Looking for (2 Replies)
Discussion started by: mkashif
2 Replies

8. Shell Programming and Scripting

awk miscellaneous doubts

In this following command: awk 'BEGIN{ORS=""}1' what does '1' signifies that comes after closing curly brace '}' of awk? I guess, it does not mean 'first occurrence' because I verified that. And, pls tell me how to override or suppress awk's field variables like $1, $2.. by positional... (7 Replies)
Discussion started by: royalibrahim
7 Replies

9. UNIX for Dummies Questions & Answers

Operators

I am trying to understand Does the following: {tmp+=$10} Mean take $10 and add them all up and call it tmp thanks! (2 Replies)
Discussion started by: llsmr777
2 Replies
Login or Register to Ask a Question