Languages
[Edit]
EN

Bash - condition to permit script execution only under Linux

11 points
Created by:
Theodora-Battle
528

In this short article, we would like to show what kind condition should be added at the begining of the Bash script to let execute the script only under Linux.

Quick solution:

#!/bin/bash

if ! [[ "$OSTYPE" =~ ^"linux" ]];
then
    echo "Script can be executed only under Linux!"
    exit 1
fi

# script body here ...

See also

  1. Bash - detect operating system
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - condition to permit script execution only under Linux
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join