千家信息网

linux系统shell脚本显示找不到文件怎么解决

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,linux系统shell脚本显示找不到文件怎么解决?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。linux source shell脚本
千家信息网最后更新 2026年11月02日linux系统shell脚本显示找不到文件怎么解决

linux系统shell脚本显示找不到文件怎么解决?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

linux source shell脚本显示找不到文件

例子:

[root@localhost osc]# sh a.sh a.sh: line 4: source: 1.sh: file not found[root@localhost osc]# cat a.sh #!/bin/bashcd /data/osc/bin/if [ -f 1.sh ];thensource 1.shfi

刚开始,还以为权限问题,然后给权限,但结果还是一样

man source ,找到原因了。source时找filename的问题。

source 命令找filename是在当前的shell环境下找的,如果没有反斜线,就在path中找,如果没有就没有。

source filename [arguments]              Read  and  execute commands from filename in the current shell environment and return the exit status of the last command exe-              cuted from filename.  If filename does not contain a slash, file names in PATH are used to find the directory containing file-              name.   The  file  searched  for  in  PATH  need  not be executable.  When bash is not in posix mode, the current directory is              searched if no file is found in PATH.  If the sourcepath option to the shopt builtin command is turned off, the  PATH  is  not              searched.   If  any  arguments  are  supplied, they become the positional parameters when filename is executed.  Otherwise the              positional parameters are unchanged.  The return status is the status of the last command exited within the script  (0  if  no              commands are executed), and false if filename is not found or cannot be read.

如下方式都可以:

1、将脚本所在的目录加到PATH中

2、加上相对路径或绝对路径

3、就算是当前目录也得加./

看完上述内容,你们掌握linux系统shell脚本显示找不到文件的解决方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!

脚本 问题 文件 系统 内容 原因 方法 更多 权限 目录 路径 束手无策 为此 例子 命令 对此 所在 技能 斜线 方式 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 湖北九亚互联网络科技有限公司 互联网 科技 迪茉互联网科技 互联网科技缩写 易通互联网络科技有限公司 时间互联网络科技 互联网科技视频素材 科技类的互联网平台 华脉科技工业互联网产品 北京大学互联网科技怎么样 北京华百购互联网科技有限公司 华服互联网科技官网 佛山市拉法互联网科技有限公司 互联网数据科技专业 中科明德北京互联网科技 滨湖区互联网智能科技产品有哪些 智帮互联网科技公司最近动向 互联网风格科技公司名称 10位科技互联网大佬 上海旺乐尼互联网科技有限公司 西安纸贵互联网科技有限公司 新华互联网科技学院 易互联网科技有限公司 广西拼得多互联网科技有限公司 青岛中康互联网医疗科技有限公司 山东有哪些互联网科技公司 每天都有哪些好的互联网科技 山东大美朱楼互联网科技有限公司 广州梦谷互联网科技有限公司领导 科技互联网经济论坛
0