Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set alias with quotes and double quotes in command [duplicate]

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?

like image 673
voy Avatar asked Jan 02 '13 14:01

voy


People also ask

How do you quote a double quote?

In American English, use double quotation marks for quotations and single quotation marks for quotations within quotations. In British English, use single quotation marks for quotations and double quotation marks for quotations within quotations.

How do you escape characters with double quotes?

To cause the C compiler to interpret the double quotation mark as a character, precede the double quotation mark with the C escape character, the backslash (\). The following example illustrates the correct syntax for the query in Table 1: EXEC SQL select col1 from tab1 where col1 = '\"';

What is double quote in C++?

In C and C++ the single quote is used to identify the single character, and double quotes are used for string literals. A string literal “x” is a string, it is containing character 'x' and a null terminator '\0'. So “x” is two-character array in this case. In C++ the size of the character literal is char.


1 Answers

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.

like image 61
Rubens Avatar answered Oct 25 '22 23:10

Rubens