Skip to content

Instantly share code, notes, and snippets.

@nasa9084
Last active May 21, 2024 02:49
Show Gist options
  • Select an option

  • Save nasa9084/caee63465acb712d43301c488534e7b5 to your computer and use it in GitHub Desktop.

Select an option

Save nasa9084/caee63465acb712d43301c488534e7b5 to your computer and use it in GitHub Desktop.

Revisions

  1. nasa9084 revised this gist May 21, 2024. 1 changed file with 10 additions and 5 deletions.
    15 changes: 10 additions & 5 deletions jq.sh
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,16 @@

    readonly version="0.0.1"

    while getopts hv OPT
    for opt in ${@}
    do
    case "${OPT}" in
    "h") echo jq.sh: filter JSON using jq or jnv transparently && exit 0;;
    "v") echo jq.sh version "${version}" && exit 0;;
    case "${opt}" in
    "-h")
    echo A jq/jnv transparent wrapper
    exit 0
    ;;
    "-v")
    echo jq.sh version "${version}"
    ;;
    esac
    done

    @@ -36,4 +41,4 @@ case "${#}" in
    cat | jq "${@}"
    fi
    ;;
    esac
    esac
  2. nasa9084 revised this gist May 20, 2024. 1 changed file with 0 additions and 0 deletions.
    Empty file modified jq.sh
    100644 → 100755
    Empty file.
  3. nasa9084 created this gist May 20, 2024.
    39 changes: 39 additions & 0 deletions jq.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/bin/bash

    readonly version="0.0.1"

    while getopts hv OPT
    do
    case "${OPT}" in
    "h") echo jq.sh: filter JSON using jq or jnv transparently && exit 0;;
    "v") echo jq.sh version "${version}" && exit 0;;
    esac
    done

    case "${#}" in
    0)
    if [ -t 0 ]
    then
    echo error: no argument is passed
    exit 1
    else
    cat | jnv
    fi
    ;;
    1)
    if [ -t 0 ]
    then
    jnv "${1}"
    else
    cat | jq "${1}"
    fi
    ;;
    *)
    if [ -t 0 ]
    then
    jq "${@}"
    else
    cat | jq "${@}"
    fi
    ;;
    esac