I'm trying to upload certificates(just created) to some storage.
So I can read all certificates in my folder and want to use content of each of this file to a variable in a loop.
#!/bin/bash
dir="${0%/*}"
#for f in $(cat $dir"/"*.crt)
# do
# data='{"certificate_data":'"$f"'}'
#done
url="localhost:50183/api/v0.1/Certificates"
data='{"certificate_data":'$(cat $dir"/"*.crt)'}'
echo "$data"
So I got all certificates in one time but I need to get in $data each of content of files in a loop with correct form something like:
{"certificate_data":"<certificate_data_from_file>"}
{"certificate_data":"<certificate_data_from_file>"}
......
and so on
I know that I should use another one loop but don't know how.
Be grateful for any tips!
$(cat file.txt)can be replaced with$(< file.txt).data. But perhaps within your sameforloop you would havedata_file='{"certificate_data":'"$f"'}'thendata_cert='{"certificate_data":'$(< $dir"/"*.crt)'}'followed by whatever logic you want to do with$data_fileand$data_cert.for f in $(cat $dir"/"*.crt) do data='{"certificate_data":'"$f"'}' doneand it's work without it, but filled all certificates in 1 "certificate_data" and I need to put 1 certificate to 1 "certificate_data"data="${data}{\"certificate_data\":....}"