运行sh程序的时候显示:
# ./convert_edition.sh
bash: ./convert1.sh: /usr/bin/bash: bad interpreter: No such file or directory
这是文件编码格式问题,有时出现在windows环境写代码传到linux环境执行的时候。网上有很多种格式转换方式,比如用notepad++转换,使用python脚本转换等。
我们可以简单的安装 dos2unix来解决这个问题,
root@eve-ng:~# apt install dos2unix
Reading state information... Done
The following NEW packages will be installed
dos2unix
0 to upgrade, 1 to newly install, 0 to remove and 0 not to upgrade.
Need to get 68.7 kB of archives.
After this operation, 306 kB of additional disk space will be used.
Get:1 http://uk.archive.ubuntu.com/ubuntu xenial/universe amd64 dos2unix amd64 6.0.4-1 [68.7 kB]
Fetched 68.7 kB in 0s (1,583 kB/s)
Selecting previously unselected package dos2unix.
(Reading database ... 226301 files and directories currently installed.)
Preparing to unpack .../dos2unix_6.0.4-1_amd64.deb ...
Unpacking dos2unix (6.0.4-1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up dos2unix (6.0.4-1) ...
装完之后,执行
root@eve-ng:~# dos2unix convert1.sh
dos2unix: converting file convert1.sh to Unix format ...
再运行sh脚本就OK了