Example, for your amusement:
$ f=/etc/os-release; . $f; cat $f | sed -re 's/(.*)=.*/printf "%20s: %s\n" "\$1" "$1"/'
printf "%20s: %sn" "$NAME" "$NAME"
printf "%20s: %sn" "$VERSION" "$VERSION"
printf "%20s: %sn" "$ID" "$ID"
printf "%20s: %sn" "$ID_LIKE" "$ID_LIKE"
printf "%20s: %sn" "$PRETTY_NAME" "$PRETTY_NAME"
printf "%20s: %sn" "$VERSION_ID" "$VERSION_ID"
printf "%20s: %sn" "$HOME_URL" "$HOME_URL"
printf "%20s: %sn" "$SUPPORT_URL" "$SUPPORT_URL"
printf "%20s: %sn" "$BUG_REPORT_URL" "$BUG_REPORT_URL"
printf "%20s: %sn" "$PRIVACY_POLICY_URL" "$PRIVACY_POLICY_URL"
printf "%20s: %sn" "$VERSION_CODENAME" "$VERSION_CODENAME"
printf "%20s: %sn" "$UBUNTU_CODENAME" "$UBUNTU_CODENAME"
$
… now the actual problem;
how do I execute this in the local shell, WITHOUT the use of a temporary file!?
( so avoid anything similar to ... >z ; . z ; rm z
)
xargs cannot do it (IIUC)
source – has no such option
bash – creates a subshell, so will not see the variable values.
NOTE:
$ source <(f=/etc/os-release; . $f; cat $f | sed -re 's/(.*)=.*/printf "%20s: %s\n" "\$1" "$1"/')
$NAME:
$VERSION:
$ID:
$ID_LIKE:
$PRETTY_NAME:
$VERSION_ID:
$HOME_URL:
$SUPPORT_URL:
$BUG_REPORT_URL:
$PRIVACY_POLICY_URL:
$VERSION_CODENAME:
$UBUNTU_CODENAME:
$ source < <(f=/etc/os-release; . $f; cat $f | sed -re 's/(.*)=.*/printf "%20s: %s\n" "\$1" "$1"/')
bash: source: filename argument required
source: usage: source filename [arguments]
$ source /dev/fd/0 <(f=/etc/os-release; . $f; cat $f | sed -re 's/(.*)=.*/printf "%20s: %sn" "\$1" "$1"/')
^C # no output, CTRL-C
$
EXPECTED OUTPUT, and I repeat – without use of temporary file/scripts:
$NAME: Ubuntu
$VERSION: 20.04.4 LTS (Focal Fossa)
$ID: ubuntu
$ID_LIKE: debian
$PRETTY_NAME: Ubuntu 20.04.4 LTS
$VERSION_ID: 20.04
$HOME_URL: https://www.ubuntu.com/
$SUPPORT_URL: https://help.ubuntu.com/
$BUG_REPORT_URL: https://bugs.launchpad.net/ubuntu/
$PRIVACY_POLICY_URL: https://www.ubuntu.com/legal/terms-and-policies/privacy-policy
$VERSION_CODENAME: focal
$UBUNTU_CODENAME: focal