alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"'

Display environment vars only, using set

Normally the bash builtin command 'set' displays all vars and functions. This just shows the vars. Useful if you want to see different output then env or declare or export. Alias 'sete' shows sets variables alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"' Alias setf shows the functions. alias setf='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/,\$p"' Also see: At the very least, some cool sed commands! From my .bash_profile
Sample Output
BASH_VERSINFO=([0]="3" [1]="2" [2]="25" [3]="1" [4]="release" [5]="i686-redhat-linux-gnu")
GREP_OPTIONS='-D skip --binary-files=without-match'

These Might Interest You

  • If you have multiple displays or monitors the DISPLAY environment variable will tell X where to send the output. This is very handy for setting up a mediacenter at home. You can plugin the computer to the TV and then ssh to the computer and set the DISPLAY as above, then run your program and it will show up on the TV.

    DISPLAY=:0.0; export DISPLAY
    sb · 2009-11-23 14:28:39 0
  • This starts an X server using Xvfb(1) (no graphics hardware required), then starts a VNC server on the display. Change :1 if there's a conflict with an existing display, and change 800x600x24 to suit your tastes (24 is the bit depth, 800x600 is the size). This command obviously requires X be installed, and also x11vnc(1); both are available via your favourite package manager. You can also use another VNC server of your choosing, as long as DISPLAY is set to the display of Xvfb(1). To change your desktop environment (the default is twm(1), which is rather fail), you can add it to your ~/.xinitrc file (see the startx(1) manpage for details).

    startx -- `which Xvfb` :1 -screen 0 800x600x24 && DISPLAY=:1 x11vnc
    Spaz · 2009-04-01 03:51:35 0
  • This uses some tricks I found while reading the bash man page to enumerate and display all the current environment variables, including those not listed by the 'env' command which according to the bash docs are more for internal use by BASH. The main trick is the way bash will list all environment variable names when performing expansion on ${!A*}. Then the eval builtin makes it work in a loop. I created a function for this and use it instead of env. (by aliasing env). This is the function that given any parameters lists the variables that start with it. So 'aae B' would list all env variables starting wit B. And 'aae {A..Z} {a..z}' would list all variables starting with any letter of the alphabet. And 'aae TERM' would list all variables starting with TERM. aae(){ local __a __i __z;for __a in "$@";do __z=\${!${__a}*};for __i in `eval echo "${__z}"`;do echo -e "$__i: ${!__i}";done;done; } And my printenv replacement is: alias env='aae {A..Z} {a..z} "_"|sort|cat -v 2>&1 | sed "s/\\^\\[/\\\\033/g"' From: Show Sample Output

    for _a in {A..Z} {a..z};do _z=\${!${_a}*};for _i in `eval echo "${_z}"`;do echo -e "$_i: ${!_i}";done;done|cat -Tsv
    AskApache · 2010-10-27 07:16:54 0
  • Will print the host associated with the current stdin. This is useful to set the DOIT_SERVER for the doit remote execution agent ( ) export DOIT_HOST=$(who -m | sed 's/.*(\(.*\)).*/\1/') Note that SSH_CLIENT variable can be lost if you use su or sudo (if set to reset vars) Show Sample Output

    who -m | sed 's/.*(\(.*\)).*/\1/'
    keymon · 2011-09-22 10:28:30 3
  • Allows you to change the value of an environment variable only for the execution of the command in the line. (corrected) Show Sample Output

    magmax · 2009-03-12 07:04:44 2
  • A script that checks if your environment is correctly configured for using cobbler. Show Sample Output

    cobbler check
    w00binda · 2009-04-27 10:28:29 0

What Others Think

Just thinking how is this different from: env
b_t · 391 weeks and 5 days ago
OK, did not notice your work on 'setf' before. There seems no built-in alternative to 'setf' though.
b_t · 391 weeks and 5 days ago
It's much different than env, thats odd if sete and env are displaying the exact same environment. Thats because env is a command, usually in /bin/env or /usr/bin/env so it is executed like any other executable, by calling execve with the current environment, but not the bash environment, whereas set is a shell builtin which shows all the bash internal variables and the current executing environment of bash. For example, do a cat /proc/$$/environ On my machine, env does not show the following vars that sete shows: BASH BASH_ARGC BASH_ARGV BASH_LINENO BASH_SOURCE BASH_VERSINFO BASH_VERSION COLUMNS DIRSTACK EUID GROUPS HOSTTYPE IGNOREEOF INTERACTIVE LINES LOGIN_SHELL MACHTYPE MAILCHECK OPTERR OPTIND OSTYPE PPID PS2 PS3 PS4 SECONDS SHELLOPTS SOURCED UID But if you want to see ALL the hidden variables within bash, check out:
AskApache · 391 weeks and 5 days ago
cat /proc/$$/environ vs: cat /proc/$PPID/environ or with strace you can compare: strace -v -f -e trace=execve /bin/env and stracing bash is harder, but: strace -v -f -e trace=execve /bin/bash -i -l -c 'set'
AskApache · 391 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: