V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MarioLuisGarcia
V2EX  ›  分享发现

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

  •  
  •   MarioLuisGarcia · 2014-08-08 15:03:15 +08:00 · 4335 次点击
    这是一个创建于 3542 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    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
    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   ·   我们的愿景   ·   实用小工具   ·   1207 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:13 · PVG 02:13 · LAX 11:13 · JFK 14:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.