Get the App
SLTechnology News&Howtos  ›  Servers  › 

What if linux can't find the file when executing the script?

Shulou Source: shulou.com Published: 2022-06-03 00:04:52 09月22日 Update

What if linux can't find the file when executing the script? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

When executing an existing shell script file on Linux, it prompts you that the file does not exist.

The general reason at this time is that the system in which your shell script is written is not consistent with the system in which you execute the script. For example, when you write a script in window system, you will encounter this problem when you copy it to Linux system. The reason is that .sh files edited under windows are in dos format, while linux can only execute scripts in unix format.

Because pressing the enter key once under dos/window is actually entering "enter (CR)" and "line feed (LF)", while pressing the enter key once under Linux/unix only enters "line feed (LF)", the modified sh file will have an extra CR on each line, so the command will not be found in error when running under Linux.

In addition, this problem may also occur when you download the shell script file in the source file on github using the windows system, and when you extract it and copy it to the Linux system for execution.

Solution:

We can view the format format of the file through the vi editor. The steps are as follows:

1. First open the file with the vi command

[root@localhost test] # vi test.sh

two。 Use the: set ff command in vi command mode

You can see that the format of the file is

Fileformat=dos

3. Modify the file format to unix

Use vi/vim to modify the file format

Command:: set ff=unix

Or: set fileformat=unix

Then: wq saves and exits and re-executes the script.

On the linux script execution can not find the file how to solve the problem shared here, I hope the above content can be of some help to you, if you still have a lot of doubts unsolved, you can follow the industry information channel to learn more related knowledge.

Tags: File script system format command problem that is the reason enter key copy is in more help solution input easy consistent simple content method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Shulou Information Xiaomi MariaDB