When executing a pre-existing shell script file under a Linux system, it prompts you that the file does not exist.
The general reason for this is that your shell script is written in a system that is inconsistent with your execution script, such as the script you wrote in the window system, and you will encounter this problem when you copy it to the Linux system. The reason is that the. sh file edited under Windows is in DOS format, and Linux can only execute scripts formatted as UNIX. Because under the Dos/window press the return key to actually enter is "returns (CR)" and "line break (LF)", and Linux/unix press the return key to enter only "line break (LF)", so the modified SH file in each line will be more than one CR, So Linux running under the error can not find the command. In addition, when you use Windows system to download the source file containing the shell script file on the GitHub, this problem may also occur when you extract and copy the Linux system execution.
Solution:
We can view the format of the file by using the VI editor. The steps are as follows:
1. First open file with vi command
[Root@localhost test]# VI test.sh
2. Use in VI Command mode: SET FF command
You can see the format of the file as
Fileformat=dos
3. modify file format to Unix
Use Vi/vim to modify file format
Command:: Set Ff=unix
Or:: Set Fileformat=unix
Then: Wq save exit, rerun script is normal