V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
sungnix
V2EX  ›  Bash

请问如何在 alias 命令里传递参数?

  •  
  •   sungnix · Dec 18, 2020 · 1972 views
    This topic created in 1956 days ago, the information mentioned may be changed or developed.

    比如要压缩一个目录需要输入下面的 zip 命令:
    zip -r git.zip git

    现在我想通过 alias 简化输入的命令:
    alias zp='zip -r $1.zip $1'

    但是我发现执行 zp git 后生成的文件是 .zip 而不是希望的 git.zip
    请问如何才能把文件名传递给 zip 命令?

    2 replies    2020-12-18 15:23:25 +08:00
    Vegetable
        1
    Vegetable  
       Dec 18, 2020   ❤️ 1
    sungnix
        2
    sungnix  
    OP
       Dec 18, 2020
    确实用 function 可以实现,感谢~
    `function zp() { zip -r $1.zip $1; }`
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1147 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 23:08 · PVG 07:08 · LAX 16:08 · JFK 19:08
    ♥ Do have faith in what you're doing.