昨天自行领悟了 Linux 的传送门技术.... - V2EX
MarioLuisGarcia

昨天自行领悟了 Linux 的传送门技术....

  •  
  •   MarioLuisGarcia Aug 8, 2014 5347 views
    This topic created in 4318 days ago, the information mentioned may be changed or developed.
    why I need a teleport?
    If you always need to send files to a particular directory, you'll need it.


    How to use the teleport?
    Pass the items to the [-|-] (it's a door!). Pong! They are on the moon now.
    Or: teleport file1 file2 file3 ... file42

    How to make the teleport:
    1. make a file in anywhere named teleport.sh
    2. type in: mv $* /path/to/destination/assume/it_is/moon
    3. go home directory, edit your .bashrc
    4. put this alias command in it: alias teleport='sh /path/where/you/put/teleport.sh'
    5. execute command: . .bashrc
    6. Done!

    May you enjoy your teleport~
    15 replies    2014-08-09 23:07:24 +08:00
    oohusl
    nbsp;   1
    oohusl  
       Aug 8, 2014
    艹 hao gao duan de yang zi
    pfitseng
        2
    pfitseng  
       Aug 8, 2014
    我忍不住给你32个赞。。。
    nicai000
        3
    nicai000  
       Aug 8, 2014
    啊? 一个简单到爆意义不大的alias被蹩脚地写成了脚本? 不过看起来很高级的样子啊难道是我没懂?
    xiiing
        4
    xiiing  
       Aug 8, 2014   1
    rsync是不是更好一点,如果文件较多
    MarioLuisGarcia
        5
    MarioLuisGarcia  
    OP
       Aug 8, 2014
    @nicai000 用alias如何move任意个文件到某个地方,求教。很显然我是没有领悟你知道的那种方法,然后才使用这种方法的。
    nicai000
        6
    nicai000  
       Aug 8, 2014
    @MarioLuisGarcia alias teleport='mv -t /path/destination/'

    或者写成函数

    teleport() {
    mv $* /path/destination/
    }
    Doubear
        7
    Doubear  
       Aug 8, 2014
    Fuck ! My english is very pool !
    Youmu
        8
    Youmu  
       Aug 8, 2014
    233, 不忍直视啊。
    iptux
        9
    iptux  
       Aug 8, 2014
    1. .sh 不以 #! 作为第一行么?
    2. 正确的引用命令行参数的不是 "$@" 么?
    3. 不做参数检查么?

    MarioLuisGarcia
        10
    MarioLuisGarcia  
    OP
       Aug 8, 2014
    @iptux
    1.从规范的角度而言是应该加shebang的,不过bash能自动识别就没加了
    2.昨天查找命令的时候有看到一个stackoverflow上讨论$@和$*的,但$*能用,就没看$@的说明了
    3.传送门只管传,不管来的是小猫,小狗还是地球。。

    另,借这宝地,向你请教一个问题,感觉你应该知道怎么解决。
    在shell脚本里如何表示第二个参数到第无限个参数?
    rrfeng
        11
    rrfeng  
       Aug 8, 2014   1
    @MarioLuisGarcia
    $2- $n = shift;$@
    MarioLuisGarcia
        12
    MarioLuisGarcia  
    OP
       Aug 8, 2014
    @rrfeng 看来还是得看看$@啊
    MarioLuisGarcia
        13
    MarioLuisGarcia  
    OP
       Aug 8, 2014
    @rrfeng teleport能传参数之后就可以环游太阳系了!
    MarioLuisGarcia
        14
    MarioLuisGarcia  
    OP
       Aug 8, 2014
    @iptux 仔细看了下, $* 是把所有参数当成一个argument, $@是把所有参数当成多个argument, 在这儿$*和$@都行。

    但是如果要支持往teleport里传参数旅行到其他行星的话,是需要用到$@了。
    br9852000
        15
    br9852000  
       Aug 9, 2014
    我怎么感觉好无聊啊!
    About     Help     Advertise     Blog     API     FAQ     Solana     5648 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 41ms UTC 06:29 PVG 14:29 LAX 23:29 JFK 02:29
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86