Skip to content

Instantly share code, notes, and snippets.

@webdevel
Last active December 5, 2021 14:27

Revisions

  1. webdevel revised this gist Mar 10, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions getopts.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    GetOpts Example
    --------------
    Shell script example of using GetOpts with Git Submodule.

    ```bash
    #!/bin/sh

  2. webdevel created this gist Mar 10, 2013.
    42 changes: 42 additions & 0 deletions getopts.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    GetOpts Example
    --------------
    ```bash
    #!/bin/sh

    REMOTE=origin
    BRANCH=dev

    showHelp()
    {
    cat << EOF
    Pull in the latest changes from remote branch.
    Usage: $(basename $0) [OPTIONS]
    OPTIONS:
    -h Show this help message
    -b Branch name (default: $BRANCH)
    -r Remote alias (default: $REMOTE)
    EOF
    }

    while getopts "hr:b:" option; do
    case $option in
    r)
    REMOTE=$OPTARG
    ;;
    b)
    BRANCH=$OPTARG
    ;;
    h)
    showHelp
    exit
    ;;
    esac
    done

    git pull $REMOTE $BRANCH
    git submodule foreach git pull $REMOTE $BRANCH
    ```