V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
mystryl
V2EX  ›  问与答

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

  •  
  •   mystryl · 2016-08-18 10:39:18 +08:00 · 4850 次点击
    这是一个创建于 2780 天前的主题,其中的信息可能已经有所发展或是发生改变。

    借用了 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
    

    就如上三个脚本

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

    感觉这不对啊。。
    mystryl
        5
    mystryl  
    OP
       2016-08-18 15:30:36 +08:00
    @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  
       2016-08-18 15:36:57 +08:00
    @mystryl 还要其他环境变量那没法了。。你加个 source ~/.bash_profile 试试
    arphone
        7
    arphone  
       2016-08-18 16:00:23 +08:00
    @mystryl sorry,看错了,应该是 cd 到 hexo 所在目录,然后 ./hexo ;或者就是把 hexo 可执行文件路径加到 path 环境变量里去
    mystryl
        8
    mystryl  
    OP
       2016-08-19 08:51:52 +08:00
    感谢 ‪@Orz_C ‬ terminal 里面 echo $PATH ,然后在你的脚本第一行加上 PATH=刚才的输出
    成功了。
    zhanglintc
        9
    zhanglintc  
       2016-08-19 12:12:59 +08:00
    你在 terminal 里能用, 那是 PATH 里有比如 hexo 这个二进制文件的路径. 但是你在使用 alfred 的时候并没有这个路径. 所以你要写绝对地址.

    我认为是这样的.
    lkai
        10
    lkai  
       2020-06-22 18:23:24 +08:00
    @mystryl 加了好像不行呢~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5836 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 06:19 · PVG 14:19 · LAX 23:19 · JFK 02:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.