I have the following use case. I need to read from an YAML file using yq
v4 PEM keys. It's then important to keep the trailing newlines otherwise a future reading of those PEM keys would miserably fail.
I haven't found a way in Bash to read a PEM from an Yaml file and store it in a variable keeping the trailing newlines.
Naturally if I would use $()
Bash would remove the trailing new lines.
Do you have any other idea?
CodePudding user response:
I seriously doubt that you genuinely need to do this (see comments on the question), but using a process substitution to feed input to the read
command (configured to expect end-of-input to be signified by a NUL rather than a newline) will work:
IFS='' read -r -d '' input < <(yq ... && printf '\0')
Be sure you check stored contents with echo "$input"
or declare -p input
, not echo $input
. (That's true in the command-substitution case too).