Home >Operation and Maintenance >Linux Operation and Maintenance >What to do if linux cannot find the file

What to do if linux cannot find the file

藏色散人
藏色散人Original
2019-11-14 09:12:307084browse

What to do if linux cannot find the file

What should I do if Linux cannot find the file?

linux source shell script shows that the file cannot be found

Example:

[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

At first, I thought there was a permission problem, and then I gave permission, but the result was still the same

man source, found the reason. The problem of finding filename when source.

source The command to find filename is found in the current shell environment. If there is no backslash, it is found in the path. If there is no backslash, it is not found.

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.

The following methods are available:

1. Add the directory where the script is located to PATH

2. Add a relative path or absolute path

3. Even the current directory must be added./

Recommended: "Linux Tutorial"

The above is the detailed content of What to do if linux cannot find the file. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn