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

Alfred 中用/bin/bash/运行脚本 command not found

  •  
  •   mystryl · Aug 18, 2016 · 5809 views
    This topic created in 3539 days ago, the information mentioned may be changed or developed.

    借用了 V 友的一个 hexo 脚本,快速 cl g d 的。 但是只有将命令在 terminal 运行的时候才正常,无论是 bash 还是 zsh 运行,在 debug 里都报错

    /bin/bash: line 3: hexo: command not found

    试试看 where 吧? /bin/bash: line 3: where: command not found

    囧 where 都找不到。。 但这两条命令在 terminal 里运行都是正常的。 求问怎么了。。

    hexodir=(${HOME}/Dropbox/hexo)
    cd ${hexodir}
    hexo clean
    
    hexodir=(${HOME}/Dropbox/hexo) 
    cd ${hexodir}
    hexo generate
    
    hexodir=(${HOME}/Dropbox/hexo)
    
    cd ${hexodir}
    hexo deploy
    

    就如上三个脚本

    Supplement 1  ·  Aug 19, 2016
    感谢 ‪@Orz_C ‬ terminal 里面 echo $PATH ,然后在你的脚本第一行加上 PATH=刚才的输出
    成功了。
    10 replies    2020-06-22 18:23:24 +08:00
    lumen
        1
    lumen  
       Aug 18, 2016
    大概是 PATH 变量里的路径没有包含命令所在路径
    UnisandK
        2
    UnisandK  
       Aug 18, 2016
    LS+1 ,要不直接写绝对路径
    arphone
        3
    arphone  
       Aug 18, 2016
    既然已经 cd ${hexodir} 了,应该 ./hexo xxxx 就可以了
    mystryl
        4
    mystryl  
    OP
       Aug 18, 2016
    @arphone [2016-08-18 15:03:07][ERROR: action.script] /bin/bash: line 2: ./hexo: No such file or directory

    感觉这不对啊。。
    mystryl
        5
    mystryl  
    OP
       Aug 18, 2016
    @lumen 请问如何添加?捣鼓了一个 echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile 好像无效


    @UnisandK 直接调用 /usr/local/bin/hexo ?
    '''
    hexodir=(${HOME}/Dropbox/hexo)
    cd ${hexodir}
    /usr/local/bin/hexo clean
    '''
    [2016-08-18 15:29:56][ERROR: action.script] env: node: No such file or directory
    UnisandK
        6
    UnisandK  
       Aug 18, 2016
    @mystryl 还要其他环境变量那没法了。。你加个 source ~/.bash_profile 试试
    arphone
        7
    arphone  
       Aug 18, 2016
    @mystryl sorry,看错了,应该是 cd 到 hexo 所在目录,然后 ./hexo ;或者就是把 hexo 可执行文件路径加到 path 环境变量里去
    mystryl
        8
    mystryl  
    OP
       Aug 19, 2016
    感谢 ‪@Orz_C ‬ terminal 里面 echo $PATH ,然后在你的脚本第一行加上 PATH=刚才的输出
    成功了。
    zhanglintc
        9
    zhanglintc  
       Aug 19, 2016
    你在 terminal 里能用, 那是 PATH 里有比如 hexo 这个二进制文件的路径. 但是你在使用 alfred 的时候并没有这个路径. 所以你要写绝对地址.

    我认为是这样的.
    lkai
        10
    lkai  
       Jun 22, 2020
    @mystryl 加了好像不行呢~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1320 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 17:19 · PVG 01:19 · LAX 10:19 · JFK 13:19
    ♥ Do have faith in what you're doing.