Przejdź do treści

Czytanie Argumentów skryptu – BASH – TODO

The strategy for parsing options in Bash is to cycle through all arguments passed to your shell script, determine whether they are an option or not, and then shift to the next argument. Repeat this process until no options remain.

Start with a simple Boolean option (sometimes called a switch or a flag):

Skrypt sprawdza czy jest argument ’-d’ podany przy uruchamianiu

pi@chris:/> ./skrypt.sh -d 
# OR
pi@chris:/> ./skrypt.sh xDDD -d 

#!/bin/bash
for i in "$@";
do
    if [ "$i" = "-d" ];
    then
         DEBUG="1";
         echo "Dodano do argumentu parametr '-d '"
    else
        echo "Brak argumentu parametr '-d' "
    fi

done

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Wymagane pola są oznaczone *