Created
September 29, 2023 11:58
-
-
Save Alina-chan/80a91013e3e7be14a178f3ec6b716912 to your computer and use it in GitHub Desktop.
How to read multiple Publisher objects from publish response and write PUBLISHER_N in .env file
This file contains 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
# Get a space-separated string of publisher object IDs | |
PUBLISHER_IDS_STRING=$(echo "$newObjs" | jq -r 'select(.objectType | contains("::Publisher")).objectId') | |
# Read the Publishers string into an array using a while loop | |
declare -a PUBLISHERS | |
while IFS= read -r line; do | |
PUBLISHERS+=("$line") | |
done <<< "$PUBLISHER_IDS_STRING" | |
# Create a temporary file to hold the environment variables | |
temp_env=$(mktemp ./temp_env) | |
# Iterate over the array and write each publisher ID to the temporary file | |
for i in "${!PUBLISHERS[@]}"; do | |
echo "PUBLISHER_$((i + 1))=${PUBLISHERS[i]}" >> "$temp_env" | |
done | |
{ | |
# rest of environment variables | |
cat "$temp_env" # This line will add the PUBLISHER_n variables to the .env file | |
# rest of environment variables | |
} > .env | |
# Clean up the temporary file | |
rm "$temp_env" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment