第1行:?#!/ usr/bin/sh:尝试执行shell脚本时找不到

Don*_*Don 2 bash shell

我有一个名为autoinstall的脚本:

#!/usr/bin/sh
echo "Installasi membutuhkan free space minimal 2MB, pastikan ada punya cukup space di router anda"
read -p "Anda yakin ingin melanjutkan installasi?(y/n) " -n 1 -r
echo ""
if [[ $REPLY = ^[Yy]$ ]]
then
    cd /
    cd /tmp/
    tar -xvf OpenWrt_Angel_Beats_Edition_v1.3.3.tar -C /
    chmod -R 744 /root/crt
    chmod 744 /www/wget/wget_download.sh
    chmod 744 /usr/bin/gsm
    chmod 744 /usr/bin/profile
    opkg update && opkg install elinks
    cp /etc/rc.local /etc/rc.local.backup
    cat > /etc/rc.local << END
    #!bin/sh
    # /etc/rc.local: Local system initialization script.
    #
    # Put any local startup commands in here. Also, if you have
    # anything that needs to be run at shutdown time you can
    # make an /etc/rc.d/rc.local_shutdown script and put those
    # commands in there.
    sh /www/wget/wget_download.sh > /dev/null 2>&1 &
    exit 0
END
    killall sh /www/wget/wget_download.sh
    sh /www/wget/wget_download.sh > /dev/null 2>&1 &
    echo "File backup /etc/rc.local.backup telah dibuat, gunakan file ini untuk mengembalikan konfigurasi rc.local anda yang dulu jika diperlukan"
    echo "Installasi selesai. Jangan lupa di akun openvpn yang digunakan (/root/crt/xxx.ovpn) tambahkan baris ini:
    script-security 2
    up client-connect.sh"
else
    echo ""
    echo "Installasi dibatalkan"
fi
Run Code Online (Sandbox Code Playgroud)

我放在第一行的每个命令总是得到上面的错误(line 1:xxx not found),我确定我输入了正确的命令,甚至echo给出了这样的错误,我该如何解决?

Aar*_*lla 6

这里可能有两个问题:

  1. 该文件不存在.通常,因为sh路径是/bin/sh,所以它应该是#!/bin/sh

  2. 您正在Windows上编辑该文件.Windows使用CR + LF作为行尾.Unix(和Linux)只使用LF.因此对于Linux,该命令读取"执行/bin/sh<CR>并且sh<CR>不存在.

解决方案:编辑文件时,请确保使用Unix行结尾.