Commands tagged environment (13)

  • Print environment (system) information using Perl.


    3
    perl -e 'print map { $_ .= "$ENV{$_}\n" } (keys %ENV)'
    MarxBro · 2012-10-13 23:38:28 6
  • 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: http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    2
    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 5
  • Grabs the cmdline used to execute the process, and the environment that the process is being run under. This is much different than the 'env' command, which only lists the environment for the shell. This is very useful (to me at least) to debug various processes on my server. For example, this lets me see the environment that my apache, mysqld, bind, and other server processes have. Here's a function I use: aa_ps_all () { ( cd /proc && command ps -A -opid= | xargs -I'{}' sh -c 'test $PPID -ne {}&&test -r {}/cmdline&&echo -e "\n[{}]"&&tr -s "\000" " "<{}/cmdline&&echo&&tr -s "\000\033" "\nE"<{}/environ|sort&&cat {}/limits' ); } From my .bash_profile at http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    1
    cd /proc&&ps a -opid=|xargs -I+ sh -c '[[ $PPID -ne + ]]&&echo -e "\n[+]"&&tr -s "\000" " "<+/cmdline&&echo&&tr -s "\000\033" "\nE"<+/environ|sort'
    AskApache · 2010-10-22 02:34:33 14
  • Same as previous but compatible with BSD/IPSO


    1
    ps ewwo command PID | tr ' ' '\n' | grep \=
    egreSS · 2011-09-15 12:07:46 3
  • 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: http://www.commandlinefu.com/commands/view/6899/print-all-environment-variables-including-hidden-ones At the very least, some cool sed commands! From my .bash_profile http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    0
    alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"'
    AskApache · 2010-11-17 23:58:01 10
  • Python virtual environment creation.


    0
    $sudo aptitude install python-virtualenv; virtualenv --no-site-packages jpaenv; source jpaenv/bin/activate
    moulip · 2011-04-21 08:28:18 3
  • This exports all lines of input file as environment variables, assuming each line is like these: OH=YEAH FU=UUUU


    0
    while read line; do export $line; done < <(cat input)
    dario · 2013-03-15 08:14:04 10
  • Sometimes there are just no variables such as $DESKTOP_SESSION, $GDMSESSION, or $WINDOWMANAGER. Show Sample Output


    0
    ls -l /usr/share/xsessions/
    puresky · 2014-01-17 05:09:18 7
  • Normally executing 'set' returns a vast amount of information, including the source code of every function and variable within the environment - including those that are part of the shell. By using the -o posix argument, bash runs temporarily in POSIX mode for this command, which simplifies expressions and leaves out the shell's own functions and definitions - leaving a much smaller, more useful list. Show Sample Output


    0
    alias allvars=' ( set -o posix; set ) | less'
    incidentnormal · 2016-03-04 14:04:45 12

  • 0
    eval "unset $(printenv | grep -ioP '(?:https?|no)_proxy' | tr '\n' ' ')"
    acavagni · 2019-06-28 10:40:41 35
  • This function is used to set environmental variables from a list of alternatives depending on what's installed on the system. It returns the first program found in the list. Example usage: export BROWSER=$(find_alternatives chromium-browser google-chrome opera firefox firefox-bin iceweasel konqueror w3m lynx) . export EDITOR=$(find_alternatives vim nano pico emacs kate) . export PAGER=$(find_alternatives vimpager less most more pg)


    -1
    find_alternatives(){ for i;do which "$i" >/dev/null && { echo "$i"; return 0;};done;return 1;}
    eightmillion · 2011-01-06 19:53:46 3

  • -1
    printenv
    tatwright · 2012-10-14 17:47:18 4

  • -1
    perl -e 'print "$_=$ENV{$_}\n" for keys %ENV'
    sgikas · 2012-11-12 13:14:28 4

What's this?

commandlinefu.com 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


Check These Out

force unsupported i386 commands to work on amd64
The above was done using the i386 flashplayer plugin, and was installed on a AMD64 machine running an AMD64 kernel and AMD64 programs. the resulting plugin install ultimately didn't work for swiftfox (but worked for iceweasel) without also covering it with a nspluginwrapper which took a bit of fenangaling to get to work (lots of apt-getting) but it is a nice feature to be able to trick installers that think you need i386 into running on a amd64, or at least attempting to run on amd64. Enjoy

Gets the english pronunciation of a phrase
Usage examples: say hello say "hello world" say hello+world

Generat a Random MAC address
Generate a random MAC address with capital letters

Extract tarball from internet without local saving

Check whether laptop is running on battery or cable
The original proc file doesn't exist on my system.

Install pip with Proxy
Installs pip packages defining a proxy

Track X Window events in chosen window
After executing this, click on a window you want to track X Window events in. Explaination: "xev will track events in the window with the following -id, which we get by greping window information obtained by xwininfo"

dont execute command just add it to history as a comment, handy if your command is not "complete" yet

list files recursively by size

Get the IP address
gives u each configured IP in a seperate line.


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: