nezhazheng
V2EX  ›  问与答

如何在执行某个命令的时候指定一个特定的目录。

  •  
  •   nezhazheng · Jul 1, 2014 · 3456 views
    This topic created in 4357 days ago, the information mentioned may be changed or developed.
    OS X下,如何在执行某个命令的时候指定一个特定的目录。
    比如我想要我当前的命令在XXX目录下执行,但是我又不想cd过去。
    2 replies    2014-07-02 08:09:58 +08:00
    lululau
        1
    lululau  
       Jul 1, 2014
    function under() {
    local dir=$1
    shift
    local old_pwd="$PWD"
    cd "$dir"
    "$@"
    cd "$old_pwd"
    }

    under / ls -l

    这样?
    stevenyou
        2
    stevenyou  
       Jul 2, 2014
    @lululau 我一般是 cd /the/directory/ && ls -l && cd -
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2713 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:05 · PVG 20:05 · LAX 05:05 · JFK 08:05
    ♥ Do have faith in what you're doing.