Issue
I'm on a linux machine in the command line. I would like to find all of the environment variables with same value.
In my hypothetical/simplified example, let's imagine I run the command printenv
and that gives me the output of:
SHELL=/bin/bash
GOOGLE_CLOUD_SHELL=true
GOOGLE_CLOUD_PROJECT=qwiklabs-gcp-04-331618d6c19
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
CLOUD_SHELL=true
DEVSHELL_PROJECT_ID=qwiklabs-gcp-04-331618d6c19
GCLOUD_PROJECT=qwiklabs-gcp-04-331618d6c19
I am trying to find redundant environment variables. I would like a command that shows me all of the environment variables with the value of qwiklabs-gcp-04-331618d6c19
. So I would like a command to show me this output:
GOOGLE_CLOUD_PROJECT=qwiklabs-gcp-04-331618d6c19
DEVSHELL_PROJECT_ID=qwiklabs-gcp-04-331618d6c19
GCLOUD_PROJECT=qwiklabs-gcp-04-331618d6c19
I would also be happy with this output:
GOOGLE_CLOUD_PROJECT
DEVSHELL_PROJECT_ID
GCLOUD_PROJECT
How can I do this?
Solution
I would like a command that shows me all of the environment variables with the value of qwiklabs-gcp-04-331618d6c19
Most probably I would just do:
env -0 | grep -zx '[^=]*=qwiklabs-gcp-04-331618d6c19' | tr '\0' '\n'
Answered By - KamilCuk Answer Checked By - Pedro (WPSolving Volunteer)