I made a simple script to change the hostname and IP of an Alpine VM I have tried to install bash and run it, have also tried with sh I don't know what else to do or try. Can someone please help me I will leave the script and outputs.
script
#!/bin/bash
#hostname change
read -p "New hostname " newhostname
echo "$newhostname" > /etc/hostname
sed -i s/alpine-blank/$newhostname/g /etc/hosts
hostname -F /etc/hostname
hostname
echo ________________________________________
#Change IP to staic
read -p "New static IP " nsip
sed -i s/#//g /etc/network/interfaces
sed -i s/ip/$nsip/g /etc/network/interfaces
sed -i s/hm/$newhostname/g /etc/network/interfaces
sed -i 's/iface eth0 inet dchp/#iface eth0 inet dchp/g' /etc/network/interfaces
service networking restart
ip a
echo ________________________________________
#New motd
echo "IP: $nsip
Hostname: $newhostname
Alpine Linux 3" > /etc/motd
echo ________________________________________
#updates
apk update
apk upgrade
echo ________________________________________
#Reboot Y/N
while true; do
read -p "confirm reboot. [Y/N]: " yn
case $yn in
[Yy]* ) reboot; break;;
[Nn]* ) exit;;
esac
done
script output ran with bash
alpine-blank:~# ls
setup.sh
alpine-blank:~# bash
alpine-blank:~# echo $0
bash
alpine-blank:~# ./setup.sh
bash: ./setup.sh: /bin/bash^M: bad interpreter: No such file or directory
alpine-blank:~#
script ran with sh and shebang defining /bin/sh
alpine-blank:~# ls
setup.sh
alpine-blank:~# sed -n 1p setup.sh
#!/bin/sh
alpine-blank:~# sh
alpine-blank:~# echo $0
sh
alpine-blank:~# ./setup.sh
sh: ./setup.sh: not found
alpine-blank:~# sh ./setup.sh
: not found line 2:
': bad variable nameme
: No such file or directory
: not found line 8: hostname
: not found line 9:
________________________________________
: not found line 11:
': bad variable name
: No such file or directorys
: No such file or directorys
: No such file or directorys
: No such file or directorys
'
BusyBox v1.34.1 (2022-04-04 10:19:27 UTC) multi-call binary.
Usage: ip [OPTIONS] address|route|link|tunnel|neigh|rule [ARGS]
OPTIONS := -f[amily] inet|inet6|link | -o[neline]
ip addr add|del IFADDR dev IFACE | show|flush [dev IFACE] [to PREFIX]
ip route list|flush|add|del|change|append|replace|test ROUTE
ip link set IFACE [up|down] [arp on|off] [multicast on|off]
[promisc on|off] [mtu NUM] [name NAME] [qlen NUM] [address MAC]
[master IFACE | nomaster]
ip tunnel add|change|del|show [NAME]
[mode ipip|gre|sit] [remote ADDR] [local ADDR] [ttl TTL]
ip neigh show|flush [to PREFIX] [dev DEV] [nud STATE]
ip rule [list] | add|del SELECTOR ACTION
: not found line 20:
________________________________________
: not found line 22:
: not found line 29:
________________________________________
: not found line 31:
' is not an apk command. See 'apk --help'.
' is not an apk command. See 'apk --help'.
: not found line 35:
________________________________________
: not found line 37:
./setup.sh: line 41: syntax error: unexpected word (expecting "in")
alpine-blank:~#