Home > OS >  Shell - Remove space before variable in alias
Shell - Remove space before variable in alias

Time:12-15

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 ?

CodePudding user response:

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"
}
  • Related