Skip to main content
added 64 characters in body; edited tags
Source Link
xhienne
  • 18.3k
  • 2
  • 59
  • 71
  1. the if in m) isn't working, in that if I omit the argument, Bash intercedes and kicks me out of the session;

    git add -A -bash: option requires an argument -- m Invalid parameter. logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed.

    git add -A
    -bash: option requires an argument -- m
    Invalid parameter.
    logout
    Saving session...
    ...copying shared history...
    ...saving history...truncating history files...
    ...completed.
    

    [Process completed]

  2. After running: wsgc -m "Yo!" -p, I get kicked out of the session.

    git add -A git commit -m "Yo." git push logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed.

    git add -A
    git commit -m "Yo."
    git push
    logout
    Saving session...
    ...copying shared history...
    ...saving history...truncating history files...
    ...completed.
    

    [Process completed]

  1. the if in m) isn't working, in that if I omit the argument, Bash intercedes and kicks me out of the session;

    git add -A -bash: option requires an argument -- m Invalid parameter. logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed.

    [Process completed]

  2. After running: wsgc -m "Yo!" -p, I get kicked out of the session.

    git add -A git commit -m "Yo." git push logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed.

    [Process completed]

  1. the if in m) isn't working, in that if I omit the argument, Bash intercedes and kicks me out of the session;

    git add -A
    -bash: option requires an argument -- m
    Invalid parameter.
    logout
    Saving session...
    ...copying shared history...
    ...saving history...truncating history files...
    ...completed.
    

    [Process completed]

  2. After running: wsgc -m "Yo!" -p, I get kicked out of the session.

    git add -A
    git commit -m "Yo."
    git push
    logout
    Saving session...
    ...copying shared history...
    ...saving history...truncating history files...
    ...completed.
    

    [Process completed]

Source Link

Bash: Help honing a custom function

I'm learning Bash, and I've written a basic function:

wsgc () {
    # Wipe the global variable value for `getopts`.
    OPTIND=1;
    echo "git add -A";
    while getopts m:p option;
    do
        case "${option}"
        in
            m)
                COMMIT_MESSAGE=$OPTARG
                if [ "$COMMIT_MESSAGE" ]; then
                    echo "git commit -m \"$COMMIT_MESSAGE.\""
                else
                    echo "A commit message is required."
                    exit
                fi
                ;;
            p)
                echo "git push"
                exit
                ;;
            \?)
                echo "Invalid parameter."
                exit
                ;;
        esac
    done
}

However, I'm struggling with a couple of things:

  1. the if in m) isn't working, in that if I omit the argument, Bash intercedes and kicks me out of the session;

    git add -A -bash: option requires an argument -- m Invalid parameter. logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed.

    [Process completed]

  2. After running: wsgc -m "Yo!" -p, I get kicked out of the session.

    git add -A git commit -m "Yo." git push logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed.

    [Process completed]

Any advice would be much appreciated.