What is the best and most correct way to use Linux commands in bash scripts in terms of path to it? Is that correct to use only ip addr show
, relying on shell path, or should I find a path to the command first (like with whereis ip
or command -v ip
), assign the output to some variable and then use that?
相关问题
- How to get the return code of a shell script in lu
- JQ: Select when attribute value exists in a bash a
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- bash print whole line after splitting line with if
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- Check if directory exists on remote machine with s
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Is there a non-java, cross platform way to launch
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
Personally, I just rely on the PATH and invoke "bare" commands.
If you don't trust the user's PATH, you can reset it to a minimal default:
I tend to set the path to utilities at the top of my path, avoiding any dependency on PATH. One potential attack is to set the PATH before running a bash script. Setting the path for each utility is painful, but it can protect against that sort of attack.
In cases where you are authoring for multiple environments in which the utilities are found in different places, e.g. Debian and MacOS, I check for the path, e.g.