Write a shell script under Windows, upload to Linux run the Times wrong:
Copy Code code as follows:
[Root@localhost test]#./test.sh
-bash:./test.sh:/bin/sh^m:bad interpreter:no such file or directory
Test.sh Source:
Copy Code code as follows:
#!/bin/sh
echo "Test Shell"
Because I am not familiar with the shell, to find colleagues to understand the cause of communication, the main reason is that test.sh I edited in Windows and uploaded to the Linux system to execute the format of the. sh file is in DOS format. 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.
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 that the format of the change file is
Copy Code code as follows:
3. modify file format to Unix
Use Vi/vim to modify file format
Command:: Set Ff=unix
Or:: Set Fileformat=unix
Then: Wq Save the exit on it