Languages
[Edit]
EN

Bash - condition to permit script execution only under Linux

11 points
Created by:
Marcin
19550

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

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