LinuxQuestions.org
Visit Jeremy's Blog.
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
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:57 AM.

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
Open Source Consulting | Domain Registration