14

I want to set an alias for the command:

expect -c 'spawn ssh usr@ip -p 57022 ; expect password ; send "pass\n" ; interact'

but quotes from alias alias_name="" and from command doesn't like each other.

I tried combinations with ', " and `, but all of these failed. How can I do that?

Rubens
  • 14,478
  • 11
  • 63
  • 92
voy
  • 1,568
  • 2
  • 17
  • 28
  • 1
    lol, no, I asked this question 10 months earlier – voy Nov 23 '17 at 15:03
  • you are right, but the other one is more viewed & upvoted and has better answers - better to point people there from here than vice versa – LangeHaare Nov 23 '17 at 15:26
  • cf https://meta.stackoverflow.com/a/252017/8131703 - *If the new question is a better question or has better answers, then vote to close the old one as a duplicate of the new one.* (sorry, no insult to your question, but the answers are better on the other one) – LangeHaare Nov 23 '17 at 15:30

1 Answers1

27

A simple solution is to create a function, instead of an alias:

function function_name() {

    expect -c 'spawn ssh usr@ip -p 57022 ; \
        expect password ; send "pass\n" ; interact'

}

So you can call function_name, and it will work just as fine as with an alias.

If you still want to use an alias, just escape the inner "'s:

alias alias_name="expect -c 'spawn ssh usr@ip -p 57022 ; expect password ; send \"pass\n\" ; interact'"

and it should work.

Rubens
  • 14,478
  • 11
  • 63
  • 92
  • 1
    great, function works fine! quotes escaping failed (bash: !Ak\n\": event not found) thank you very much :) – voy Jan 02 '13 at 14:22