bobier2
bobier2

Reputation: 147

Shell - Remove space before variable in alias

Typing myAlias 10 or even better myAlias10 should execute ssh [email protected]

alias myAlias="ssh [email protected].${1}" produces ssh [email protected].

When I echo it, it is displayed as ssh [email protected]. 10 with a space.

How to remove the space ?

Upvotes: 3

Views: 965

Answers (1)

choroba
choroba

Reputation: 241968

If you use double quotes, the variable is expanded right when parsing the alias definition.

Aliases don't take parameters, they just append the remaining words - you can't "remove the space", it has already been parsed.

Use a function instead, functions take arguments:

myssh () {
    ssh [email protected]."$1"
}

Upvotes: 3

Related Questions