Last active
March 29, 2021 08:04
-
-
Save Loupax/4f3aeda1eb31187b446d4399941092d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Dependencies: xargs, jq | |
# | |
# Example usages: | |
# fsToJson file file2 file2 | |
# fsToJson $(ls file*) | |
# will generate something like | |
# { | |
# "file": "file contents", | |
# "file2": "file2 contents", | |
# "file3": "file2 contents" | |
# } | |
function files_to_json(){ | |
printf '%s\n' "$@" | | |
xargs -L 1 -I {} jq -sR --arg key {} '{ ($key): .}' {} | jq -s 'add' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment