简体   繁体   English

通过桌面图标运行 bash 脚本时找不到节点命令

[英]Node command not found when bash script is run through desktop icon

I'm trying to run a node app from a desktop icon using a bash script.我正在尝试使用 bash 脚本从桌面图标运行节点应用程序。 The desktop icon executes the bash script and this one is supposed to run the node app.桌面图标执行 bash 脚本,这个应该运行节点应用程序。 If I run the bash script manually, node app is launched normally, but when I do double click on the desktop icon, then the bash script returns: line 3 node: command not found and it finish with Bye (see the script below).如果我手动运行 bash 脚本,节点应用程序会正常启动,但是当我双击桌面图标时,bash 脚本会返回: line 3 node: command not found ,并以 Bye 结束(参见下面的脚本)。

Here the .desktop icon content and the bash script.这里是.desktop图标内容和 bash 脚本。

the.desktop:桌面:

[Desktop Entry]
Version=1.0
Name=Todo
Comment=Shortcut to my app
Exec='/home/myuser/app/run_todo.sh'
Icon=/home/myuser/Pictures/donatello.svg
Terminal=true
Type=Application
Categories=Application

The bash script: bash 脚本:

#!/bin/bash
cd /home/myuser/app/todo_app/
node ./app.js
echo "Bye"
$SHELL

I'm using Ubuntu 20.04 and Node 12.14.1 installed through nvm.我正在使用通过 nvm 安装的 Ubuntu 20.04 和节点 12.14.1。

A workmate solved the problem.一个同事解决了这个问题。 Just add只需添加

PATH="/home/myuser/.nvm/versions/node/v12.14.1/bin:$PATH"

after the #!/bin/bash line.#!/bin/bash行之后。

So the bash script is finally:所以 bash 脚本最终是:

#!/bin/bash
PATH="/home/myuser/.nvm/versions/node/v12.14.1/bin:$PATH"

cd /home/myuser/app/todo_app/
node ./app.js
echo "Bye"
$SHELL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM