Question

Is there a good way to do multiple substitutions for aliasing a command?

For example

alias cmd = 'ssh -R $1:$2:$1:$2 $3 | something {$1, $2, $3}'
cmd 127.0.0.1 1234 server

Something like this..

Actually, this doesn't really make any sense to pipe the output like this, but similar syntax is what I'd like to see.

It's be nice to have named mappings too, but just indexes is fine.

Using awk perhaps?

Was it helpful?

Solution

How about using a shell function instead?:

$ cmd() { echo ssh -R $1:$2:$1:$2 $3 ; echo something {$1, $2, $3} ; }
$ cmd 127.0.0.1 1234 server
ssh -R 127.0.0.1:1234:127.0.0.1:1234 server
something {127.0.0.1, 1234, server}

OTHER TIPS

You have to define it by using a function. Example:

cmd () { echo -e "$1\n$2" | grep "$1"; }

Don't forget the space between { and echo.

This would result in the following behaviour:

$ cmd hello world
hello
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top