"E: Invalid operation update" error while running shell scripts in WSL

10,824

Solution 1

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

Solution 2

For any one who is using Notepad++ go to Edit => EOL Conversion => Unix(LF) same as show in the picture below enter image description here

Share:
10,824

Related videos on Youtube

AnjanaAK
Author by

AnjanaAK

Updated on May 25, 2022

Comments

  • AnjanaAK
    AnjanaAK almost 2 years

    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?

  • moztemur
    moztemur over 4 years
    Thanks a lot. I encountered the problem while using Linux VM on Windows via Vagrant and modifying synced sh files from Windows Notepad++ as CRLF. Just changed it to LF and it has worked.
  • zeocrash
    zeocrash about 4 years
    This was a huge help for me. Fixed the problem.