Skip to content

Instantly share code, notes, and snippets.

@unfor19
Created July 24, 2020 10:54
Show Gist options
  • Save unfor19/f3762edc2ef028453032b4305fa0a1a0 to your computer and use it in GitHub Desktop.
Save unfor19/f3762edc2ef028453032b4305fa0a1a0 to your computer and use it in GitHub Desktop.
  • Using the help flag

    bash example.sh -h
    
    Usage: bash example.sh -n Willy --gender male -a 99
    
          --person_name  |  -n  [Willy]              What is your name?
          --age          |  -a  [Required]
          --gender       |  -g  [Required]
          --location     |  -l  [chocolate-factory]  insert your location
  • Using default values

    $ bash example.sh -a 99 --gender male
    
    Name:      Willy
    Age:       99
    Gender:    male
    Location:  chocolate-factory
  • Providing all arguments

    $ bash example.sh -a 23 --gender male -l neverland -n meir
    
    Name:      meir
    Age:       23
    Gender:    male
    Location:  neverland
  • Providing an empty required argument

    $ bash example.sh -a 99 --gender
    
    [ERROR] Empty argument: gender
    
    Usage: bash example.sh -n Willy --gender male -a 99
    
          --person_name  |  -n  [Willy]              What is your name?
          --age          |  -a  [Required]
          --gender       |  -g  [Required]
          --location     |  -l  [chocolate-factory]  insert your location
  • Providing an unknown argument

    $ bash example.sh -a 99 -u meir
    
    [ERROR] Unknown argument: -u
    
    Usage: bash example.sh -n Willy --gender male -a 99
    
          --person_name  |  -n  [Willy]              What is your name?
          --age          |  -a  [Required]
          --gender       |  -g  [Required]
          --location     |  -l  [chocolate-factory]  insert your location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment