FedoraForum.org - Fedora Support Forums and Community
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2008
    Location
    Nairobi Kenya
    Posts
    565

    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?

  2. #2
    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

  3. #3
    Join Date
    Jan 2008
    Location
    Nairobi Kenya
    Posts
    565
    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)

  4. #4
    Join Date
    Jan 2008
    Location
    Nairobi Kenya
    Posts
    565
    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?

  5. #5
    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

  6. #6
    Join Date
    Jan 2008
    Location
    Nairobi Kenya
    Posts
    565
    Thanks

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

    is exactly what I needed

Similar Threads

  1. help with a bash script
    By dan sawyer in forum Using Fedora
    Replies: 5
    Last Post: 6th July 2009, 04:07 PM
  2. Bash Script Help:
    By jguy in forum Servers & Networking
    Replies: 6
    Last Post: 22nd December 2006, 06:41 PM
  3. Convert bash script to perl script
    By homey in forum Programming & Packaging
    Replies: 1
    Last Post: 2nd September 2006, 04:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •