在bash脚本中使用Linux命令的正确方法 [英] Correct way to use Linux commands in bash script
本文介绍了在bash脚本中使用Linux命令的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就bash脚本的路径而言,在bash脚本中使用Linux命令的最佳和最正确的方法是什么?仅依靠外壳路径使用 ip addr show
是正确的吗?还是我应该先找到该命令的路径(例如使用 whereis ip
或 command-v ip
),将输出分配给某个变量,然后使用该变量?
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?
推荐答案
我个人只是依靠PATH并调用裸"命令.
Personally, I just rely on the PATH and invoke "bare" commands.
如果您不信任用户的PATH,可以将其重置为最小默认值:
If you don't trust the user's PATH, you can reset it to a minimal default:
PATH=$(/usr/bin/getconf PATH)
grep "$pattern" "$file"
这篇关于在bash脚本中使用Linux命令的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文