请教shell 脚本的搜索路径

sws_martian 2009-12-28 10:40:20
编写一个脚本,然后在任何目录下都能执行,应该怎么设置?
...全文
125 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sws_martian 2009-12-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hairetz 的回复:]
用绝对路径。
应该没有其他问题了。

[/Quote]

这种方法我知道,但是能不能这样,比如我在$HOME/BIN 目录下创建一个ver.sh,然后在该用户的任何目录下键入ver.sh都能运行?
  • 打赏
  • 举报
回复
用绝对路径。
应该没有其他问题了。
昵称很不好取 2009-12-28
  • 打赏
  • 举报
回复
在你的shell脚本中不要用绝对路径,全部使用相对路径~~
sws_martian 2009-12-28
  • 打赏
  • 举报
回复
找到了:

Path Search
When locating a command, the shell first looks to see if it has a shell function by that name. Then it looks
for a builtin command by that name. If a builtin command is not found, one of two things happen:

1. Command names containing a slash are simply executed without performing any searches.

2. The shell searches each entry in PATH in turn for the command. The value of the PATH variable should be a
series of entries separated by colons. Each entry consists of a directory name. The current directory may
be indicated implicitly by an empty directory name, or explicitly by a single period.

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧