是否有像〜这样的特殊路径前缀,表示“在PATH中随处搜索”?我知道这是只提供可执行基本名称时的默认行为,但具有像a = b这样奇特的可执行文件名称,我只能使用路径调用它,无论是完整的还是相对的,如./a=b。如果我只提供basename a = b,bash会将其解释为变量赋值。PATH路径前缀
Q
PATH路径前缀
3
A
回答
3
没有这样的前缀。如果您的唯一目的是执行带有“奇怪”字符的文件名,则不需要它:引用这些字符,例如'a=b'
或a\=b
。然后,bash的解析和扩展会导致您的命令的第一个单词是a=b
,它会像其他任何命令名一样在路径中查找。
如果要查找路径中的程序但不执行该程序,请使用command -v
。 (还有其他内置的效果相同,command -v
具有便携的优点(这是一个bash内置的,它在POSIX中)。不要使用which
,它是一个外部命令,不可靠且不便携。)
If你想查找包含a=b
的all the directories in the path,你可以使用type -a
。
type -aP a=b
+0
感谢您的见解。迄今为止,我认为最好的答案。 –
4
0
我个人使用引号,但另一种可能是:
(exec a=b)
1
的command
内置正好为此目的而设计,即寻找一个命令(不是别名,也不是一个函数)。
command a=b
应该这样做。从bash的手册:
command [-pVv] command [arg ...] Run command with args suppressing the normal shell function lookup. Only builtin commands or commands found in the PATH are executed. If the -p option is given, the search for command is performed using a default value for PATH that is guaranteed to find all of the standard utilities. If either the -V or -v option is supplied, a description of command is printed. The -v option causes a single word indicating the command or file name used to invoke command to be displayed; the -V option produces a more ver‐ bose description. If the -V or -v option is supplied, the exit status is 0 if command was found, and 1 if not. If neither option is supplied and an error occurred or command cannot be found, the exit status is 127. Otherwise, the exit status of the command builtin is the exit status of command.
相关问题
- 1. Git子树前缀路径
- 2. 删除路径前缀
- 3. 删除文件:从URL文件路径///前缀:///前缀从URL路径
- 4. 共同路径前缀JSON读取
- 5. 模块的节点路径前缀
- 6. Rails的URL路径时摆脱前缀
- 7. 创建POST路径没有前缀
- 8. 具有可选路径前缀
- 9. 春季类路径前缀区别
- 10. 前缀路由
- 11. Prepend Path前缀到所有轨道路线
- 12. 系统路径与Sys.getenv('PATH')
- 13. 路由前缀voltrb
- 14. Cakephp路由前缀
- 15. WCF ServiceRoute路由前缀是否可以包含路径值?
- 16. 如何重定向到Expressjs路由器中的前缀路径
- 17. 如何设置默认路径(路由前缀)?
- 18. C#:使用http/https前缀返回当前网络路径
- 19. 在Linux中显示完整路径而不是〜前缀路径chrome apps
- 20. 目标部署路径'...'与POM的预期路径前缀不匹配
- 21. 处理路径结尾相同并具有一组固定的路径前缀
- 22. 如何在gulp注入脚本路径中删除路径前缀?
- 23. 回形针+ AWS S3,使用我的本地路径前缀固定路径
- 24. 没有模块前缀路径路径的Rails namescoped模型对象
- 25. 角度MVC路由前缀
- 26. Rails - 前缀路由助手
- 27. 快速路由器前缀
- 28. Laravel 5路线前缀
- 29. UI路由器前缀
- 30. CakePHP的前缀路由
像这样命名您的可执行文件在一般情况下显然不是一个好主意。 – tripleee
但考虑到命令可能具有看起来像句法实体的奇怪名称,这是一个有效的问题。 ''''伪装成'/ usr/bin/test'。 – Jens