need help with bash script
New on LowEndTalk? Please read our 'Community Rules' by clicking on it in the right menu!

need help with bash script

perryoo11perryoo11 Member
edited August 2017 in Help

hey folks

i just started learning how to make my own bash scripts.
now i just need to know how to make a script that detects distribution.

i want to support:

debian

centos 6 + 7

ubuntu any version if possible

does any of you know a place to find a good tuturial?

thanks
perry

|post4vps| for a free vps for your developement| me |

Comments

  • if [ $Operating_System == "CentOS" ]

    then

    echo "CentOS";
    
    # Do this
    

    elif [ $Operating_System == "Ubuntu" ]

    then

    echo "Ubuntu";
    
    # Do that
    

    else

    echo "Unsupported Operating System";
    

    fi

    i just want it like this way if possible

    |post4vps| for a free vps for your developement| me |

  • perryoo11 said: i just want it like this way if possible

    No one's going to write the script for you.

    @MasonR posted a link that has info on how you can determine the OS and distribution. The top-voted response on that SE link shows you how very easy this is: source /etc/os-release and play with the variables.

    What is your question?

    My Advice: VPS Advice

    For LET support, please click here.

  • OS=$(lsb_release -si)
    if [ "$OS" = "Ubuntu" ] ; then
        echo "Ubuntu"
        # do whatever
    elif [ "$OS" = "CentOS" ] ; then
        echo "CentOS"
        # do whatever
    else
        echo "You're SOL."
    fi
    
    Thanked by 1perryoo11
  • perryoo11perryoo11 Member
    edited August 2017

    @raindog308 said:

    perryoo11 said: i just want it like this way if possible

    No one's going to write the script for you.

    @MasonR posted a link that has info on how you can determine the OS and distribution. The top-voted response on that SE link shows you how very easy this is: source /etc/os-release and play with the variables.

    What is your question?

    is asking for help a crime?

    and thanks @masonr

    |post4vps| for a free vps for your developement| me |

  • perryoo11 said: is asking for help a crime?

    and thanks @masonr

    Sure. Please just do some initial investigation next time though and tell us what you've tried and what didn't work. It literally took me all of 10 seconds to google the issue and find that link I posted above.

    You're not going to learn bash, as you say, if everything is spoon fed to you. That's what @raindog308 was getting at.

  • perryoo11perryoo11 Member
    edited August 2017

    @MasonR said:

    perryoo11 said: is asking for help a crime?

    and thanks @masonr

    Sure. Please just do some initial investigation next time though and tell us what you've tried and what didn't work. It literally took me all of 10 seconds to google the issue and find that link I posted above.

    You're not going to learn bash, as you say, if everything is spoon fed to you. That's what @raindog308 was getting at.

    sorry but im trying to learn i have done some research on google/other sites.
    how to detect os/distribution

    and that what i sended was the only thing i was able to find that what i though i needed.

    so said.
    sorry then i dont want to make drama here.

    edit:

    i credited you for the help in my script

    |post4vps| for a free vps for your developement| me |

  • MasonR said: You're not going to learn bash, as you say, if everything is spoon fed to you. That's what @raindog308 was getting at.

    Yup.

    My Advice: VPS Advice

    For LET support, please click here.

  • @raindog308 said:

    MasonR said: You're not going to learn bash, as you say, if everything is spoon fed to you. That's what @raindog308 was getting at.

    Yup.

    Nope

    Dont'TalkAboutLetClub Free @WSS!! Free @WSS!! Anyone see where I parked @jar car?

    upto32.com Retro at it's best

  • bsdguybsdguy Member
    edited August 2017

    Small hint: Try to avoid bash as it is by far not everywhere installed. Instead learn 'sh' scripting. While most OSs/distros have different implementations of what they call 'sh' (e.g. debian -> 'dash') it's a reasonable assumption that 'sh' scripts ("#!/bin/sh") work pretty everywhere (and, if not, require only very minor changes).
    You can look at 'sh' as a subset of bash that is available everywhere and the one shell that usually meets the posix requirement for unices.

    For googling purposes (e.g. to find tutorials or hints) you can just look for 'dash shell' (which is much easier to google than 'sh'). Moreover, debian should have quite a bit of docu on it.

    Second hint: The trick is not simply learning this or that shell but rather to "think unixish" and to know the usual tools and ways.

    Example: If adressing all unices or at least not only linux it's common practice to first call "uname -s" which tells you the basic system, i.e. 'Linux' or 'FreeBSD' and then, if linux call 'lsb_release -si', if FreeBSD call 'uname -r' etc.

    Thanked by 1bugrakoc

    My favourite prime number is 42. - \forall cpu in {intel, amd, arm}: cpu->speed -= cpu->speed/100 x irandom(15, 30) | state := hacked

  • @bsdguy said:
    Small hint: Try to avoid bash as it is by far not everywhere installed. Instead learn 'sh' scripting. While most OSs/distros have different implementations of what they call 'sh' (e.g. debian -> 'dash') it's a reasonable assumption that 'sh' scripts ("#!/bin/sh") work pretty everywhere (and, if not, require only very minor changes).
    You can look at 'sh' as a subset of bash that is available everywhere and the one shell that usually meets the posix requirement for unices.

    For googling purposes (e.g. to find tutorials or hints) you can just look for 'dash shell' (which is much easier to google than 'sh'). Moreover, debian should have quite a bit of docu on it.

    Second hint: The trick is not simply learning this or that shell but rather to "think unixish" and to know the usual tools and ways.

    Example: If adressing all unices or at least not only linux it's common practice to first call "uname -s" which tells you the basic system, i.e. 'Linux' or 'FreeBSD' and then, if linux call 'lsb_release -si', if FreeBSD call 'uname -r' etc.

    Ok thank you for the valuable tip

    |post4vps| for a free vps for your developement| me |

Sign In or Register to comment.