We use cookies to ensure you get the best experience on our website.
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
Cześć Podróżniku!
Ta strona ma nie być typowym poradnikiem w IT, Głównym jej cel to zapisanie krótkich notatek, które mogą się przydać w codziennym życiu podczas korzystania/konfiguracji różnych urządzeń np. Ustawienia DHCP na Routerze Cisco, Ustawieniu Karty sieciowej na Linuxie itp.
Wszelkie prawa zastrzeżone
Dodaj komentarz