昨天自行领悟了 Linux 的传送门技术.... - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MarioLuisGarcia
V2EX    分享发现

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

  •  
  •   MarioLuisGarcia 2014-08-08 15:03:15 +08:00 5089 次点击
    这是一个创建于 4164 天前的主题,其中的信息可能已经有所发展或是发生改变。
    why I need a teleport?
    Ifyou 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 条回复    2014-08-09 23:07:24 +08:00
    oohusl
        1
    oohusl  
       2014-08-08 15:43:46 +08:00
    艹 hao gao duan de yang zi
    pfitseng
        2
    pfitseng  
       2014-08-08 15:46:59 +08:00
    我忍不住给你32个赞。。。
    nicai000
        3
    nicai000  
       2014-08-08 15:50:59 +08:00
    啊? 一个简单到爆意义不大的alias被蹩脚地写成了脚本? 不过看起来很高级的样子啊难道是我没懂?
    xiiing
        4
    xiiing  
       2014-08-08 15:59:17 +08:00   1
    rsync是不是更好一点,如果文件较多
    MarioLuisGarcia
        5
    MarioLuisGarcia  
    OP
       2014-08-08 16:24:32 +08:00
    @nicai000 用alias如何move任意个文件到某个地方,求教。很显然我是没有领悟你知道的那种方法,然后才使用这种方法的。
    nicai000
        6
    nicai000  
       2014-08-08 16:28:47 +08:00
    @MarioLuisGarcia alias teleport='mv -t /path/destination/'

    或者写成函数

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

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

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

    但是如果要支持往teleport里传参数旅行到其他行星的话,是需要用到$@了。
    br9852000
        15
    br9852000  
       2014-08-09 23:07:24 +08:00
    我怎么感觉好无聊啊!
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2322 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 10:51 PVG 18:51 LAX 02:51 JFK 05:51
    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