LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 09-12-2009, 08:16 AM   #1
nilleso
Member
 
Registered: Nov 2004
Location: ON, CANADA
Distribution: ubuntu, RHAS, and other unmentionables
Posts: 372

Rep: Reputation: 31
expect script - for argument loop ?


in ksh/bash I often use a for loop as in the following example:
Code:
for name in bob jim jacobo henric;do
print hello $name
done
How can I do the same for loop in an expect script?

TIA!!
cheers
 
Old 09-12-2009, 09:06 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,492

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Quote:
Originally Posted by nilleso View Post
How can I do the same for loop in an expect script?
It depends on what do you want to achieve. You can either write a shell script which executes an expect script inside the for loop, passing the name as argument OR write an expect script which uses control flow statements whose syntax is the same as Tcl.
 
Old 09-13-2009, 07:09 AM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,067

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
Code:
foreach name {bob jim jacobo henric} {
   puts "hello $name"
}
jlinkels
 
Old 09-16-2009, 08:51 PM   #4
nilleso
Member
 
Registered: Nov 2004
Location: ON, CANADA
Distribution: ubuntu, RHAS, and other unmentionables
Posts: 372

Original Poster
Rep: Reputation: 31
thanks folks jlinkels solution worked for me. I often embed expect inside of shell scripts but I couldn't get the for loop to work as expected.

cheers
 
  


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
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 8 04-05-2011 09:18 AM
How To pass argument in Expect command? jprathap Linux - Newbie 3 08-27-2009 04:58 PM
Expect script help shriyer Linux - Server 3 07-08-2009 08:42 PM
Hoto run a for loop in C that depends on the program's first argument? daYz Programming 4 01-08-2007 11:59 AM


All times are GMT -5. The time now is 04:03 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration