ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Folks, I'm having a problem with a tcl escape character: the backslash.
I'm trying to create a script that calls another script. One of the parameters that is sent to the other script is a password (to use with ssh). Well, if the password is a usual string, like 'carrie', it works fine. The problem occurs when the first letter of the password is a dollar sign, like $testpass. When this password is used, tcl seems to write the string inside braces, like {$testpass}. This new value created by tcl is sent to the second script, and then my system fails, because the correct password is $testpass, and not {$testpass}.
Take good notice of the first line in the code. It cannot be /bin/sh like in the code you posted. Are you sure you posted the code verbatim?
This is the output I got:
Code:
donald_pc:~$ ./psswd.exp
spawn telnet 5622 root $testpass 172.21.1.2 md5sum /root/ipt-firewall
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {4289}
tty_raw_noecho: was raw = 0 echo = 1
However, I am not sure there is not shell expansion being used for $testpass. Have you tried to put a literal '\$testpass' in the spawn command line. I assume you get this by:
Hope you can reproduce now... Thanks by the attention...
I don understand pretty much the difference between #!/usr/bin/expect and #!/bin/sh, but I'll play a little bit with this issue and give a feedback to the forum if it works...
double quotes at the set directive does not work also.. makes no difference...
set ssh_password "\$teste"
and making both script as #!/usr/bin/expect does not work also... but if I put both as #!/bin/sh, then a total error happens.. so I'm using both as expect script now... thanks by the tip...
and you are fine. The problem is that $argv is a list. Although is have only one member it is still a list and therefore printed between {}
BTW, it is better programming style to name your files as .tcl or .exp when they contain tcl or expect code, and sh when it is a shell script. Also, be careful to put !#/usr/bin/tcl or !#/bin/sh as the first line matching whether your script is tcl or sh. And it MUST be on the first line. This:
does not work when spawning. It can only work when you call the expect program with this file as input.
Do you have special reasons to put the login part in a different file? It can be in one file, this way complicates matters a bit. (Like the passing of variables )
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.