Can't interpret variable in if statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can't interpret variable in if statement
# 1  
Old 06-25-2008
Can't interpret variable in if statement

Can someone help me out here. I can't get this piece of code to work. i.e. $ALL_EVENTS does not get interpreted in the if brackets. The first part is the code, the second part is the execution of the code. Note: $ALL_EVENTS does equal 2, but there is no value once passed to the if statement.




echo $ALL_EVENTS

if [[ $All_EVENTS -eq 2 ]]; then
echo "it works"
fi




ALL_EVENTS= 2
+ echo 2
2
+ [[ -eq 2 ]]
# 2  
Old 06-25-2008
just try with this

if [[ "$All_EVENTS" -eq "2" ]]; then
echo "it works"
fi
# 3  
Old 06-25-2008
Quote:
Originally Posted by jwholey
echo $ALL_EVENTS

if [[ $All_EVENTS -eq 2 ]]; then
echo "it works"
fi

ALL_EVENTS= 2
+ echo 2
2
+ [[ -eq 2 ]]
Is All_EVENTS vs ALL_EVENTS a typo ?
# 4  
Old 06-25-2008
Sure was a type o. Thanks. There goes the first wasted hour of my day.
# 5  
Old 06-25-2008
typeset -i ALL_EVENTS
Placing this before the script should resolve the issue
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable IF statement in awk

I have multiple requirements to run data extracts (with the same basic requriement / resulsts) however the parameters of the extracts change with each request. To help make life easier I am writing a script where the parameters for the specific request are set at the start and then used as needed.... (6 Replies)
Discussion started by: meike
6 Replies

2. Shell Programming and Scripting

Variable on If Statement

Hi, I am tasked to modify soem script and I come accross a line which I dont fully understand. I tried searching online but I couldnt get a good explanation on it. Here it the part of the code: PAY_RT=`cat $TEMPFILE | cut -f2 -d","` if ; then PAY_RT=R fi What is... (3 Replies)
Discussion started by: The One
3 Replies

3. Shell Programming and Scripting

if then else; no variable match but statement executes anyway.

My first then statement is executing even though there is no match between the variables. each subsequent if then statement is also executing. Why do they execute when there is no match in the dates? yr=`date +%y` date1=12-31-$yr date=`date +%m-%d-%y` set -vx if ; ... (6 Replies)
Discussion started by: bash_in_my_head
6 Replies

4. Shell Programming and Scripting

Select variable within a if statement

i want to select a variable created and use it in a if statement, but not getting the desired results LINE='device for 0101a01: lpd://172.25.41.111:515' prt=`echo $LINE | awk '{print $3 }' | cut -c 1-7` echo $prt My if statement to select just what i want.. IFS=$":" while read prt... (11 Replies)
Discussion started by: ggoliath
11 Replies

5. Shell Programming and Scripting

How can i assign an select statement into a variable?

I am trying to assign an select statement into a variable. Can someone hel me with this. example : a='select * from dual' echo $a should give me select * from dual But this is not working. I trying with \ before * and quotes too. (1 Reply)
Discussion started by: rdhanek
1 Replies

6. Shell Programming and Scripting

Assigning Variable to AWK statement

Hi, The following command runs on in the Korn shell prompt. however i want to output the value of this to a variable. Can anyone provide a solution? echo 'ABC,DEF,"G,HI,J",KLM,"MNi,O"'| awk -F "\"" '{for(i=1;i<=NF;i++){if(i%2)gsub("\,","~^~",$i)}}1' (2 Replies)
Discussion started by: ladarlsan
2 Replies

7. Shell Programming and Scripting

Ksh riddle: interpret variable two times?

exam is a ksh script. In command line I enter: exam 3 param_2 param_3 param_4. In exam how can I get the value of the parameter which position is specified by the first argument. Simply doing this DOES NOT work: offset=$1 value=$$offset can you figure out any possible way to interpret a... (5 Replies)
Discussion started by: i27oak
5 Replies

8. Shell Programming and Scripting

Bash: evaluating $? variable (if statement)

Hello, i'm unable to write a correct if... statement to evaluate the $? variable. Could anybody send to me an example? for example, this lines of code didn't work... if ; then etc etc if ; then etc etc Thank you in advanced. (5 Replies)
Discussion started by: aristegui
5 Replies

9. UNIX for Dummies Questions & Answers

Perl / Interpret Unix If statement

Hi all, I am a newbie, so please let me know if there is a better way to do this. I coded a perl script, that scans a Unix script and picks out certain strings (strings that precede ".log"). However I want to limit the strings it picks up based on the "If statements" in the unix script. ... (0 Replies)
Discussion started by: syera123
0 Replies

10. Shell Programming and Scripting

Using variable in case statement

I want to do this: Ex 1: case $answer in 1|2|3|4|5) echo $answer;; x) break;; *) echo "Invalid selection. Try again.";; esac But I need the part "1|2|3|4|5" to be fetched from a variable, like so: Ex 2: case $answer in $cases) echo $answer;; x) break;; *) echo "Invalid... (2 Replies)
Discussion started by: fialia
2 Replies
Login or Register to Ask a Question