linux找不到文件怎么办


本文摘自PHP中文网,作者藏色散人,侵删。

linux找不到文件怎么办

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

例子:

1

2

3

4

5

6

7

8

[root@localhost osc]# sh a.sh

a.sh: line 4: source: 1.sh: file not found

[root@localhost osc]# cat a.sh

#!/bin/bash

cd /data/osc/bin/

if [ -f 1.sh ];then

source 1.sh

fi

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

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

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

1

2

3

4

5

6

7

8

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教程

以上就是linux找不到文件怎么办的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

Linux中如何查看是否安装mysql

将弹性网卡附加到 ecs 实例上之后如何配置弹性网卡

Linux系统下有vscode吗

Linux下如何查看是否安装了apache服务

u盘安装Linux,拔除u盘无法启动系统

Linux下怎么创建目录

Linux查看数据库安装在哪

Linux中改变文件所有者的命令是什么

Linux截取命令是什么?

Linux默认的shell是什么

更多相关阅读请进入《Linux》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...