Shell script error: -bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory

Wrote a server startup script:

#!/bin/bash
 
JAVA_HOME=/usr/java/jdk1.8.0_131
 
JAVA=$JAVA_HOME/bin/java
 
nohup $JAVA -jar microservice-0.0.1-SNAPSHOT.jar -Djava.ext.dirs=$JAVA_HOME/lib &
运行后报错:

/bin/bash^M: bad interpreter: No such file or directory

The main reason is that .sh is executed in the linux system after being edited under Windows. The format of the .sh file is dos format. And linux can only execute scripts in unix format.

We can view the format of the file through the vi editor. Proceed as follows:

1: First open the current shell script file with the vi command

2: Use the :set ff command in vi command mode:

:set ff=unix

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325720872&siteId=291194637