How to print all non-environment variables?

Arcticooling

How to print all non-environment variables?

These are all the variables I've added myself since the moment the shell started, like when doing:

read abc
    123
# echo ${abc} => 123

Or

xyz='123'
# echo ${xyz} => 123

I want to print all of them, to know what was added to the memory, so I could clean it off.

Michael Homer

If you're using Bash, this command will list the names of all shell variables that are not inherited by a child process and not part of the default slate:

diff -U 1 <(set -o posix ; set |cut -d= -f1) <(exec bash -ic 'set -o posix ; set' | cut -d= -f1)|grep '^[-][^-]'|cut -d- -f2|grep -vE '^(COLUMNS|HISTFILESIZE|HISTSIZE|LINES|PIPESTATUS)$'

This produces a list of all variable names in the current shell (with set), and a list of all variable names in a newly-created subprocess running the same shell, finds all those present in the first list and not the second (with diff, the last cut, and the first grep), and trims out some Bash-specific default variables that the subprocess won't have because it's not a user-facing shell. set -o posix makes set list only the variables and not functions.

It will omit both inherited environment variables and variables you've explicitly marked for export.

Swap out bash for your shell. You'll also need to change the list of ignored variables in the last grep, and can probably lose set -o posix. If your shell doesn't have process substitution, you'll need to use temporary files instead, or platform-specific access to file descriptors (like /dev/fd).


On the other hand, if all you want to do is clear out your own local variables and functions then

exec bash

will have that effect (while also re-reading some configuration files and potentially losing local changes to shell options).

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

List all environment variables, and show if they are exported or not

분류에서Dev

Storing all environment variables in one file

분류에서Dev

How to use Monit Environment variables?

분류에서Dev

How to print all subsets of a set?

분류에서Dev

How to refer to environment variables in Cypress config files?

분류에서Dev

How to backup/export Gitlab CI environment variables?

분류에서Dev

How to assign environment variables in parallel in bash

분류에서Dev

how to use system environment variables in boto

분류에서Dev

How do I configure environment variables in cmder?

분류에서Dev

How to export Environment variables to a text file

분류에서Dev

How to set environment variables with sudo -u USER?

분류에서Dev

Vue-cli 3 Environment Variables all undefined

분류에서Dev

Get all recommended keg-only environment variables

분류에서Dev

How to define variables in non-technical style

분류에서Dev

how to set environment variables CAIROMM_CFLAGS and CAIROMM_LIBS

분류에서Dev

Accessing Environment Variables in flash

분류에서Dev

Bash - check environment variables

분류에서Dev

C++: how to print all elements in a vector of vectors

분류에서Dev

How to find all special characters and print them in a given string?

분류에서Dev

Can the environment variables for a modified environment be accessed externally?

분류에서Dev

Print all listbox items

분류에서Dev

How do I check if all elements of DataFrame are non-negative?

분류에서Dev

How to select all non-distinct rows from a DB?

분류에서Dev

how to show all the non – blank lines of a specific file

분류에서Dev

How can is initialize all variables in a Java class at once to zero

분류에서Dev

How to get all variables (and functions names) from the global scope in Jint?

분류에서Dev

How to obtain all the variables that need to be defined prior evaluating an expression in R?

분류에서Dev

How to drop all variables that do not cointain a string or another in R

분류에서Dev

Where is file that saves Environment Variables?

Related 관련 기사

  1. 1

    List all environment variables, and show if they are exported or not

  2. 2

    Storing all environment variables in one file

  3. 3

    How to use Monit Environment variables?

  4. 4

    How to print all subsets of a set?

  5. 5

    How to refer to environment variables in Cypress config files?

  6. 6

    How to backup/export Gitlab CI environment variables?

  7. 7

    How to assign environment variables in parallel in bash

  8. 8

    how to use system environment variables in boto

  9. 9

    How do I configure environment variables in cmder?

  10. 10

    How to export Environment variables to a text file

  11. 11

    How to set environment variables with sudo -u USER?

  12. 12

    Vue-cli 3 Environment Variables all undefined

  13. 13

    Get all recommended keg-only environment variables

  14. 14

    How to define variables in non-technical style

  15. 15

    how to set environment variables CAIROMM_CFLAGS and CAIROMM_LIBS

  16. 16

    Accessing Environment Variables in flash

  17. 17

    Bash - check environment variables

  18. 18

    C++: how to print all elements in a vector of vectors

  19. 19

    How to find all special characters and print them in a given string?

  20. 20

    Can the environment variables for a modified environment be accessed externally?

  21. 21

    Print all listbox items

  22. 22

    How do I check if all elements of DataFrame are non-negative?

  23. 23

    How to select all non-distinct rows from a DB?

  24. 24

    how to show all the non – blank lines of a specific file

  25. 25

    How can is initialize all variables in a Java class at once to zero

  26. 26

    How to get all variables (and functions names) from the global scope in Jint?

  27. 27

    How to obtain all the variables that need to be defined prior evaluating an expression in R?

  28. 28

    How to drop all variables that do not cointain a string or another in R

  29. 29

    Where is file that saves Environment Variables?

뜨겁다태그

보관