1

Using osascript, I'm able to tell the Terminal application to open an ssh connection in a separate terminal window, however, I run into errors when trying to pass bash variables in the script.

This script works just fine:

osascript -e 'tell app "Terminal"
    do script "ssh user@hostname -p port -L 9999:localhost:80 -i keyfile"
end tell'
...more commands...

But running a script like this one...

read -p "Port: " prt
read -p "Localhost port: " lhprt
osascript -e 'tell app "Terminal"
            do script "ssh user@hostname -p \"$prt\" -L \"$lhprt\":localhost:80 -i keyfile"
        end tell'
...more commands...

It doesn't pass the variables, i.e. the command passed in the new terminal window is

ssh user@hostname -p "$prt"

How might I format this to make it so my bash variables get fed through?

jebrii
  • 145
  • 1
  • 3
  • 7
  • Possible duplicate of [Difference between single and double quotes in bash](http://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash) – miken32 Mar 18 '16 at 04:42

1 Answers1

-1

Just invert the quote type Using single quote is preventing the shell to expand your parameters

Edit: You can close the string just around your variables too. I.e. 'this is a '$variable' in a "string".'

drAlberT
  • 22,059
  • 5
  • 34
  • 40
  • Can you give an example? I have multiple nested quotes, so I'm not certain which to switch. Right now, switching them, I'm getting 'syntax error: Expected expression, property or key form, etc. but found unknown token. (-2741)' – jebrii Mar 19 '16 at 07:50