开发者

how to use placeholder in command line in linux?

Suppose I want to copy a file:

  scp abc root@10.10.1.1:/home/user/app_abc

is开发者_运维问答 there a way can simplfy this command ,something like :

  scp abc root@10.10.1.1:/home/user/app_%1

BTW: I don't want to write a shell for it

Thanks


You don't have to write separate script file but you can always write one liner:

name=abc;cp $name app_$name

Did you mean scp by the way? I never used cp with this notation.


Try the following:

export BOO="abc" && scp $BOO root@10.10.1:/home/user/app_$BOO


you can have this command in script file (copy.sh) and use it with any file name you want as an input argument. you just need to follow the instruction :

  1. Create the the Bash Script File :

    $ gedit copy.sh

  2. Add your code to file and save it:

    #!/bin/sh

    scp $1 root@10.10.1.1:/home/user/app_$1

  3. Make file executable for any one :

    $ chmod 777 copy.sh

  4. And execute it:

    $ ./copy.sh abc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜