Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created June 5, 2019 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/bc74a07153193d7926ceda12cc4d0c6f to your computer and use it in GitHub Desktop.
Save ORESoftware/bc74a07153193d7926ceda12cc4d0c6f to your computer and use it in GitHub Desktop.
JQ does not make it easy to sanitize strings for JSON inclusion
#!/bin/bash
hist='sed '0,1d' "$HOME/my_bash_history" | wc -l' ### <<< we have some double quotes to escape
data="$( jq -nc --arg str "$hist" '{"attr": $str}' )"
echo "data: $data"
hist="$(echo "$data" | jq -r '.attr')"
echo "hist: $hist" # damnit it's back to where it was before
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment