sungnix
V2EX  ›  Bash

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

  •  
  •   sungnix · Dec 18, 2020 · 2011 views
    This topic created in 1973 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   ·   951 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 20:09 · PVG 04:09 · LAX 13:09 · JFK 16:09
    ♥ Do have faith in what you're doing.