Linux & Terminali

getopts in Bash

Në shqip: getopts në Bash

ShpjegimiSQ

getopts lexon opsione të shkurtra si -v ose -f skedari në një skript bash, që të mos i analizosh me dorë. Për opsione të gjata (--verbose) ose skripte të ndërlikuara, merr parasysh Python.

EnglishEN

getopts parses short options like -v or -f file in a bash script, so you don't hand-roll the parsing. For long options (--verbose) or complex scripts, consider Python.

Si ta mendosh

Si një recepsionist që i ndan kërkesat sipas formularit.

Lexoje në anglisht

Like a receptionist sorting requests by form type.

Shembull kodibash

while getopts "vf:" opt; do
  case $opt in
    v) verbose=1 ;;  f) file="$OPTARG" ;;
  esac
done

Terma të lidhur