Skip to content

Instantly share code, notes, and snippets.

@alxmal
Forked from dishbreak/magic_jq_task.sh
Created December 6, 2023 19:58
Show Gist options
  • Select an option

  • Save alxmal/63c0bc73cd7bf8ade27150b841ea1b29 to your computer and use it in GitHub Desktop.

Select an option

Save alxmal/63c0bc73cd7bf8ade27150b841ea1b29 to your computer and use it in GitHub Desktop.

Revisions

  1. @dishbreak dishbreak revised this gist Nov 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion magic_jq_task.sh
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ set -e
    # Function that checks if a given executable is on the path. If it isn't, prints an install message and exits.
    # Usage: check_binary EXECUTABLE_NAME INSTALL_MESSAGE
    check_binary() {
    if ! which "$1"; then
    if ! which "$1" > /dev/null; then
    # Using a subshell to redirect output to stderr. It's cleaner this way and will play nice with other redirects.
    # https://stackoverflow.com/a/23550347/225905
    ( >&2 echo "$2" )
  2. @dishbreak dishbreak created this gist Nov 2, 2018.
    29 changes: 29 additions & 0 deletions magic_jq_task.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/bash

    # Exit on the first command that returns a nonzero code.
    set -e

    # Function that checks if a given executable is on the path. If it isn't, prints an install message and exits.
    # Usage: check_binary EXECUTABLE_NAME INSTALL_MESSAGE
    check_binary() {
    if ! which "$1"; then
    # Using a subshell to redirect output to stderr. It's cleaner this way and will play nice with other redirects.
    # https://stackoverflow.com/a/23550347/225905
    ( >&2 echo "$2" )
    # Exit with a nonzero code so that the caller knows the script failed.
    exit 1
    fi
    }

    check_binary "jq" "$(cat <<EOF
    You will need jq to run this script.
    Install it using your package manager. E.g. for homebrew:
    brew install jq
    EOF
    )"

    # a dumb command that uses jq in order to provide a SSCCE snippet
    # http://sscce.org/
    jq -r ".message" <<EOF
    {"message": "hello from jq!"}
    EOF