'Passing output of sh command and placing it in a placeholder

I have a code snippet like this

GCP_REGION="us-central1"
BUCKET_NAME="$(case $GCP_REGION in us*) echo "foo-bar-us";;asia*) echo "foo-bar-asia";;europe*) echo "foo-bar-eu";;*) echo "unknown GCP region";exit 1 ;; esac)";

Now instead of saving the output of echo to BUCKET_NAME, is there a way to pass it to next command rclone mount gcs:$BUCKET_NAME /foo/bar

Using $BUCKET_NAME in rclone is failing and using the DRY principle I was hoping to not use the $BUCKET_NAME at all.



Solution 1:[1]

Here is my solution:

case $GCP_REGION in us*) echo "foo-bar-us";;asia*) echo "foo-bar-asia";;europe*) echo "foo-bar-eu";;*) echo "unknown GCP region";exit 1 ;; esac | xargs -I '{}' rclone mount gcs:{} /foo/bar

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Antonio Petricca