My command line/bash fu is extremely weak, but I'm trying to hone my abilities.  Hopefully someone can help.I wrote a super simple expect script so that I can SSH in to a headless box we're using at work, while also sending in the password (for reasons that I am unable to expand upon, we can't use public keys to automate logging in). The script:#!/usr/bin/expect -fset timeout 30spawn ssh -X ***@10.101.0.133 $argvmatch_max 100000expect *?assword:*send -- ***\rinteractThe box has a developer environment and Eclipse installed; most of the time that I'm connecting to it, I will end up tunneling straight in to Eclipse to work on some code that we keep on this box, so I usually end up using script eclipse.How can I pass the & flag in to expect so that it sees the ampersand as an argument for the ssh session I'm spawning ?  When I use script eclipse & it just backgrounds script on my machine instead of doing something on the remote machine, but I'd like to be able to send the & in to script so that when Eclipse launches on the remote box I can still use the box's shell.This is probably an incredibly silly question, but any help would be greatly appreciated.Update: I figured out escaping the ampersand (which was definitely a no duh moment for me... meh).  But this leads to a new problem.  It seems that when I pass any arguments to my script, the expect command never allows me to interact; once the passed command executes the SSH session terminates.  I'm guessing that this isn't a limitation of expect but a part of the behavior of ssh.  Thanks for your answers though.Update 2: Just for the sake of posterity, I got the behavior I wanted by modifying the script to look like this:#!/usr/bin/expect -fset timeout 30spawn ssh -X ***@10.101.0.133match_max 100000expect *?assword:*send -- ***\rsend $argvsend -- \rinteract
Pass the background flag (&) through expect and ssh
shell;ssh;expect
Geekosaur is right in pointing out that you can pass the ampersand by quoting it, (you could also escape it with like script eclipse \& ) but there is something else we could maybe suggest a better way of doing here. It seems you have written an expect script to ssh into another machine with your password and execute a command.You should know that from both a practical standpoint and a security standpoint this is not a very good solution. Practically, the whole situation is brittle and several potential situations could cause it to break, and debugging is confusing down the road. From a security standpoint it's crazy because your system password on another machine is saved in a text file somewhere!There is a better way! Key based authentication was built to solve this issue. You create key pairs --one part goes on the server on one on the client-- that are allowed to authenticate without a password. This allows you to run ssh from scripts without using expect AND without saving your password anywhere. As an extra step you could even encrypt the local key with a pass-phrase and use an agent or keyring manager to load the key into a shell before you run any scripts that will need to use it.Edit: I missed that you said you can't use public key authentication. That's crazy talk. I'm leaving my answer up for the benefit of any readers who might have also missed the requirement and don't realize that your script is a hack :)