This question already has an answer here:
这个问题在这里已有答案:
- mkdir command not found in bash script 2 answers
在bash脚本2答案中找不到mkdir命令
I'm trying to make a script to mount a disk when runned. The script is
我正在尝试制作一个脚本来运行时安装磁盘。脚本是
#!/bin/bash
PATH=$(python /home/pi/prova.py 2>1&)
sudo mount $PATH /media/Drive1
where path in our case is /dev/sda1 (checked using echo).
在我们的例子中路径是/ dev / sda1(使用echo检查)。
The error reported is ./script.sh: line3: sudo: command not found
报告的错误是./script.sh:line3:sudo:找不到命令
the script is added to /etc/sudoers using line
使用line将脚本添加到/ etc / sudoers
pi ALL=NOPASSWD: /home/pi/script.sh
The error is the same both adding and removing the sudo before mount command.
在mount命令之前添加和删除sudo的错误都是相同的。
Any idea ? Thanks in advance
任何的想法 ?提前致谢
1 个解决方案
#1
Don't use all-upper-case variable names for regular shell variables. This avoids overwriting environment variables and shell builtins (such as PATH
, used by the shell to determine where it looks for external commands) by mistake.
不要对常规shell变量使用全大写变量名。这样可以避免错误地覆盖环境变量和shell内置函数(例如,shell使用它来确定它查找外部命令的位置)。
Thus, a corrected implementation of this script may be:
因此,此脚本的更正实现可能是:
#!/bin/bash
path=$(python /home/pi/prova.py 2>1&)
sudo mount "$path" /media/Drive1
#1
Don't use all-upper-case variable names for regular shell variables. This avoids overwriting environment variables and shell builtins (such as PATH
, used by the shell to determine where it looks for external commands) by mistake.
不要对常规shell变量使用全大写变量名。这样可以避免错误地覆盖环境变量和shell内置函数(例如,shell使用它来确定它查找外部命令的位置)。
Thus, a corrected implementation of this script may be:
因此,此脚本的更正实现可能是:
#!/bin/bash
path=$(python /home/pi/prova.py 2>1&)
sudo mount "$path" /media/Drive1