Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux system shell script shows how to solve the problem if the file cannot be found

2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Linux system shell script shows that the file can not be found how to solve? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

The 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/bashcd / data/osc/bin/if [- f 1.sh]; thensource 1.shfi

At first, I thought there was a problem with permissions, and then I gave them permissions, but the result was still the same.

Man source, we found out why. The problem of finding filename when source.

The source command looks for filename in the current shell environment, if there is no backslash, in path, if not.

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.

It can be done in the following ways:

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

2. Add relative path or absolute path

3. Even the current directory has to be added. /

After reading the above, have you mastered the solution that the linux system shell script shows that the file can not be found? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 285

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report