Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 17th June 2008, 03:18 PM
Jamwa Offline
Registered User
 
Join Date: Jan 2008
Location: Nairobi Kenya
Posts: 540
Bash Script Help

Code:
#!/usr/bin/expect --

# ftp-rfc <rfc-number>
# ftp-rfc -index

# retrieves an rfc (or the index) from uunet

exp_version -exit 5.0

if {$argc!=2} {
        send_user "usage: this_script <ip_address> <packeteer_ip>\n"
        exit
}

send_user "$argv"


send_user "\n"
exit
Is my script. I copy-pasted most of it and I guess its finally stuck on me. This is my problem;

I used to do $1 to get the first parameter, $2 the second and so forth and so on. For this one, I am stuck on doing the same. I am trying an expect script here and not /usr/bin/sh


Any help?
Reply With Quote
  #2  
Old 17th June 2008, 04:10 PM
Vouters Offline
Banned
 
Join Date: Oct 2005
Posts: 190
You have to learn how to program using Tcl which expect is based upon:

Here is your script:

#!/usr/bin/expect --

# ftp-rfc <rfc-number>
# ftp-rfc -index

# retrieves an rfc (or the index) from uunet

exp_version -exit 5.0

if {$argc!=2} {
send_user "usage: $argv0 <ip_address> <packeteer_ip>\n"
exit
}

for { set i 0 } { $i < $argc} { incr i } {
puts "[lindex $argv $i]"
}

send_user "\n"
exit

Here is what it produces:
[philippe@victor script]$ ./expect.sh 127.0.0.1 telnet
127.0.0.1
telnet
Reply With Quote
  #3  
Old 17th June 2008, 04:35 PM
Jamwa Offline
Registered User
 
Join Date: Jan 2008
Location: Nairobi Kenya
Posts: 540
OK, I see that

for { set i 0 } { $i < $argc} { incr i } {
puts "[lindex $argv $i]"
}

is the main function here.

Trying to do

send_user lindex $argv $1

(to get the first variable), the shell complains that

can't read "1": no such variable
while executing
"send_user lindex $argv $1"
(file "./telnetSession" line 19)
Reply With Quote
  #4  
Old 17th June 2008, 04:35 PM
Jamwa Offline
Registered User
 
Join Date: Jan 2008
Location: Nairobi Kenya
Posts: 540
OK, I see that

for { set i 0 } { $i < $argc} { incr i } {
puts "[lindex $argv $i]"
}

is the main function here.

Trying to do

send_user lindex $argv $1

(to get the first variable), the shell complains that

can't read "1": no such variable
while executing
"send_user lindex $argv $1"
(file "./telnetSession" line 19)

Way forward?
Reply With Quote
  #5  
Old 17th June 2008, 04:40 PM
Vouters Offline
Banned
 
Join Date: Oct 2005
Posts: 190
[philippe@victor script]$ cat expect.sh
#!/usr/bin/expect --

# ftp-rfc <rfc-number>
# ftp-rfc -index

# retrieves an rfc (or the index) from uunet

exp_version -exit 5.0

if {$argc!=2} {
send_user "usage: $argv0 <ip_address> <packeteer_ip>\n"
exit
}

for { set i 0 } { $i < $argc} { incr i } {
puts "[lindex $argv $i]"
}

send_user "[lindex $argv 1]\n"
exit

[philippe@victor script]$ ./expect.sh 127.0.0.1 telnet
127.0.0.1
telnet
telnet
Reply With Quote
  #6  
Old 17th June 2008, 05:26 PM
Jamwa Offline
Registered User
 
Join Date: Jan 2008
Location: Nairobi Kenya
Posts: 540
Thanks

[lindex $argv 0], [lindex $argv 1], ..., [lindex $argv n]

is exactly what I needed
Reply With Quote
Reply

Tags
bash, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with a bash script dan sawyer Using Fedora 5 6th July 2009 04:07 PM
Bash Script Help: jguy Servers & Networking 6 22nd December 2006 05:41 PM
Convert bash script to perl script homey Programming & Packaging 1 2nd September 2006 04:24 AM


Current GMT-time: 15:54 (Saturday, 25-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat