Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.