Help With Expect Script IF with Multiple Conditions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help With Expect Script IF with Multiple Conditions
# 1  
Old 06-21-2012
Help With Expect Script IF with Multiple Conditions

I am needing to include some if statements within an expect script. These will need to have two conditions under an AND join. Upon a successful IF condition I want to set multiple variables.

I have tried a lot of variations of the below statement with no success. I have also searched the WEB with every possible combination to attempt to find the answer.

Does anyone know of what I am missing to make this work?

Variant 1 -
Code:
if { $user = "USER1" -a $mode = "PROD" } {
     set port "224"; set remote "PROD"; set archive "local;}

Variant 2
Code:
if [ $user = "USER1" -a $mode = "PROD" ]; then
     set port "224"
     set remote "PROD"
     set archive "local
fi


Last edited by Franklin52; 06-21-2012 at 02:13 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 06-21-2012
Hi.

One could Google for tcl if statement syntax. Then something like this might show up:
Code:
#!/usr/bin/env tclsh

# @(#) tcl1     Demonstrate tclsh feature.

set version [ info tclversion ]
set message " Hello, world, tcl version ($version).\n"
puts stdout $message

puts "Hey dude, how old might you be?"
gets stdin Age
if {$Age >= 0 && $Age <= 12} {
  puts "You are a child."
} elseif {$Age >= 13 && $Age <= 19} {
  puts "You are a teen."
} elseif {$Age > 19}  {
  puts "You are an adult now."
}

producing:
Code:
% ./tcl1 
 Hello, world, tcl version (8.4).

Hey dude, how old might you be?
15
You are a teen.

Best wishes ... cheers, drl
# 3  
Old 06-21-2012
drl,

Thanks for the additional information.

I began my quest creating the statement just as you have it. I am using a unix file format (LF) and my if statement was setup just like yours.

With this being the case I decided to just do the single condition if statement.

I am getting extra tokens at end of expression while executing.

My error statement is as follows
Code:
if {$user="USER1"} {
set acmode "I am USER1"
} elseif {$user="USER2"} {
set acmode "I am USER2"
}

All lines immediately end in a line feed.

I also have started looking at the search variation you listed. The search continues for what I am doing wrong.

Regards,
Slagathor

Last edited by Franklin52; 06-22-2012 at 03:42 AM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Multiple If conditions

I am analyzing one of the scripts written by another person.script is having multiple if conditions and everything are nested.The code is not formatted properly.Is there any way to identify in Unix to identify begin and end of a particular if block? (6 Replies)
Discussion started by: vamsi.valiveti
6 Replies

2. Shell Programming and Scripting

Multiple expect/send statements not working in shell script

Hi I am trying the following in my bash script which logs into my machine and runs a command. Trying to solve this using expect. The first expect statement is hit and it enters the address "10.10.0.10" but when the second expect statement is hit it exits #!/bin/bash expect -c ' spawn... (2 Replies)
Discussion started by: skorada
2 Replies

3. Shell Programming and Scripting

Multiple conditions in IF

Fellas, Am new to unix os/ and here the situation , I am trying to write multiple condition statement inside if but it throws me a error here is my piece of code , if ] && ] && ] then commands fi error : line 15 : ` can someone please advise me how to fix it Please use... (7 Replies)
Discussion started by: xeccc5z
7 Replies

4. UNIX for Dummies Questions & Answers

If + multiple conditions

Hello Unix-Forums! It has been a long time since my last post, but finally I've got a new question: I know in case you can use multiple patterns by case $var in a|b|c|ab) and so on. But how would I place an OR between if ] then ... if ] then ... I want to execute the "..." if... (3 Replies)
Discussion started by: intelinside
3 Replies

5. UNIX for Dummies Questions & Answers

multiple if conditions and EOF in a shell script

I want to create an IF condition with multiple condition, in the statement below I want to add OR EOF, can any one please advise how to do. if } != $sample ] && ; then echo ..... fi code tags please (1 Reply)
Discussion started by: analyst
1 Replies

6. Shell Programming and Scripting

multiple while loops in expect script

Hi, I am trying to incorporate multiple while loops into an expect script written in ksh shell. This is on a Solaris 10 system. Here is the code: #!/bin/ksh EXPECT=/usr/local/bin/expect exp_internal i=1 h=0 while ]; do $EXPECT << DONE set stty_init raw ... (1 Reply)
Discussion started by: cic
1 Replies

7. Shell Programming and Scripting

Help regarding multiple conditions

Hi All, I am new to shell scripting. Can any one say what is wrong in this if statement, that uses multiple conditions if then *************** else if ( -z $pcs && "$night_time_calc" > "$night_time" ) then ******************************** ... (4 Replies)
Discussion started by: ssenthilkumar
4 Replies

8. Shell Programming and Scripting

How to Use Multiple if Conditions in Shell script

if -o ] then echo "Expected valid value" The above multiple if condition is NOT working in my script. I am getting the error as '-a' not expected. Can anyone help with the syntax for this? (5 Replies)
Discussion started by: dinesh1985
5 Replies

9. Shell Programming and Scripting

multiple if conditions

Guys, Im trying to have a script that evaluates multiple conditions : test.sh: if then echo "host $1" else if then echo "host $1" else echo $1 not valid exit 1 fi when I do ./test.sh brazil1 I get: (4 Replies)
Discussion started by: bashshadow1979
4 Replies

10. UNIX for Dummies Questions & Answers

multiple conditions in if/then

Hello, I am having trouble with the syntax with a conditional statement in a BASH script involving multiple conditions. Any suggestions would be greatly appreciated! if ; then array=("${array}" "$dnNum" ) fi i receive this error: ./testscript: ' (4 Replies)
Discussion started by: grandtheftander
4 Replies
Login or Register to Ask a Question