1

In order to speed up typing of a long command, we can make an alias of a command, e.g.

alias remcopy='scp user@123.45.67.89:/home/file.txt /home/user/'

And we type user this exact command will be run.

However, is it possible only to load the command and then modify it according to the current need, e.g.

scp user@123.45.67.89:/home/file.txt /home/user/addeddir/
cerebrou
  • 476
  • 1
  • 8
  • 17

2 Answers2

1

There are two ways you can start various modifications of the command.

  • an alias can have a parameter, for example

    alias remcopy='scp user@123.45.67.89:/home/user/file.txt'
    
    remcopy targetname
    

    where targetname is selected a run time.

  • a function is more flexible than an alias. It can be a single line or big like a whole shellscript file.

    function remcopy () { scp user@123.45.67.89:/home/user/file.txt /home/user/"$1" ; }
    
    remcopy
    remcopy addeddir
    

    which can be used without a parameter and with a parameter (in order to change the name of the target file.

    You can store a small function in ~/.bashrc like you store aliases.

sudodus
  • 46,324
  • 5
  • 88
  • 152
  • 1
    This might also be handy: remcopy() { ssh host:remotefile "${1:-/home/user}"; } to provide a default value if there's no specified value. – glenn jackman Dec 04 '19 at 17:45
0

You can use variables to accomplish this.

For example:

alias something='nano ${1}'
something test.txt

Will open test.txt in nano for writing

stratus
  • 599
  • 2
  • 5