I have a shell script called setup_wsl.sh
which contains:
#!/bin/bash
echo "hai"
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
When i run the script as ./setup_wsl.sh in WSL ( installed distro is ubuntu 18.04), errors occur as:
hai
E: Invalid operation update
E: Unable to locate package
./setup_wsl.sh: 4: ./setup_wsl.sh: apt-transport-https: not found
./setup_wsl.sh: 5: ./setup_wsl.sh: ca-certificates: not found
curl: (3) Illegal characters found in URL
./setup_wsl.sh: 7: ./setup_wsl.sh: gnupg-agent: not found
: not found ./setup_wsl.sh: software-properties-common
: not found ./setup_wsl.sh:
The first command of the script works fine as it gives output "hai".
Can someone help me to find why these errors occured?
This is because of the carriage return in windows. Switch to the LF carriage with a text editor and save the new one to run the script or sed -i -e 's/\r$//' setup_wsl.sh
For any one who is using Notepad++ go to Edit => EOL Conversion => Unix(LF) same as show in the picture below
For VSCode, you just need to set it in the status bar
More details and options here https://qvault.io/clean-code/line-breaks-vs-code-lf-vs-crlf/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With