13

We can do with ease:

myalias='command param1 param2'

then myalias param3 runs

command param1 param2 param3

I need an alias which will run the same, but without the last 'space':

command param1 param2param3

For example I have many servers in /24 subnet and need to run the same command using the ip. So I want alias like command param1 192.168.0. then just run myalias 103 and the command will be applied to 192.168.0.103.

I tried to add $1 at the end of the alias but no luck.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Putnik
  • 886

1 Answers1

14

If you are happy to use a function, you can do something like:

command(){
"$1" "$2" "192.168.0.${3}"
}

If I test this with a dummy command:

mycommand(){
$1 "130.200.68.${2}"
}

$ mycommand ping 180

Would ping the server with the last section of the IP added.

  • Good idea! Would it there be a way to use also provide the autocompletion facility we get using alias? – MensSana Aug 13 '22 at 21:49