Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Comparisson between two strings is not working in shell script

This piece of code assign the output of the lsb_release -i command at the linux_distro variable and the script compares it against the first item of distributor_id array and then the second and so on. The first item of the array is "Distributor ID: Arch" and I am using arch so the linux_distro variable is supposed to be equal with the item of the array. Of course since I am posting here this does not seem to be the case.

if [ "$linux_distro" = "${distributor_id[0]}" ] || [ "$linux_distro" = "${distributor_id[1]}" ]; then 
    #checking if the yay AUR helper is available (it will be needed for some of the software installed)
    if ! command -v snap > /dev/null; then 
        echo "yay command was not found. Please install the yay AUR helper aur.archlinux.org/packages/yay from and try running the script again."
        exit 1
    fi
fi 

I tried printing out the variable values using echo that proved to me that everything is supposed to work as intended and I tried using the [[ command with the == operator, still no solution.

It is to be noted that I replaced yay with snap just because I got yay installed and not snap, so please don’t bother with that one.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can source /etc/os-release

. /etc/os-release

if [ "$ID" = "${distributor_id[0]}" ] || [ "$ID" = "${distributor_id[1]}" ]; then 
    #checking if the yay AUR helper is available (it will be needed for some of the software installed)
    if ! command -v snap > /dev/null; then 
        echo "yay command was not found. Please install the yay AUR helper aur.archlinux.org/packages/yay from and try running the script again."
        exit 1
    fi
fi 

this file is not exists on all linux distro

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading