Tag Info

New answers tagged

4

/etc/environment is a file used by PAM, meaning it is processed by a log in, which sudo bash does not do, and (from man sudoers): Command environment Since environment variables can influence program behavior, sudoers provides a means to restrict which variables from the user's environment are inherited by the command to be run. There are ...


0

I think this is POSIX portable: . <<ENV /dev/stdin $(sed -n 'H;${x;s/\(^\|\x00\)\([^=]*.\)\([^\x00]*\)/\2\x27\3\x27\n/gp}' \ /proc/$pid/environ) ENV But @Gilles makes a good point - sed will probably handle nulls, but maybe not. So there's this (I Really think so this time) actually POSIX portable method, too: s=$$SED$$ sed ...


6

In this answer, I assume a system where /proc/$pid/environ returns the environment of the process with the specified PID, with null bytes between variable definitions. (So Linux, Cygwin or Solaris (?)). Zsh export "${(@ps:\000:)$(</proc/$pid/environ)}" (Pretty simple as zsh goes: an input redirection with no command <FILE is equivalent to cat FILE. ...


4

In bash you can do the following. This will work for all possible contents of the variables and avoids eval: while IFS= read -rd '' var; do declare +x "$var"; done </proc/$PID/environ This will declare the read variables as shell variables in the running shell. To export the variables into the running shell environment instead: while IFS= read -rd '' ...


10

The following will convert each environment variable into an export statement, properly quoted for reading into a shell (because LS_COLORS, for example, is likely to have semicolons in it), then sources it. [The printf in /usr/bin, unfortunately, generally doesn't support %q, so we need to call the one built into bash.] . <(xargs -0 bash -c 'printf ...


1

I can't do much more right now, but it looks like you can use switches like --rc-file, or --profile, etc. man bash ... If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive ...


2

Using source and process substitution: source <(sed -r -e 's/([^\x00]*)\x00/export \1\n/g' /proc/1/environ) Shortly: . <(sed -r -e 's/([^\x00]*)\x00/export \1\n/g' /proc/1/environ) Using eval and command substitution: eval `sed -r -e 's/([^\x00]*)\x00/export \1\n/g' /proc/1/environ` The sed call can be replaced with an awk call: awk ...


-2

eval \`(cat /proc/1/environ; echo) | tr '\000' '\n'\`


2

set reports not only environment variables but also shell variables and, on some shells, functions. Use env | wc -c to get the size of the environment. The environment size is indirectly limited by the maximum size of the arguments to execve (which consist of the environment plus the command line arguments). You can get the applicable value of this limit ...


5

When I type set | wc the result is 9571 bytes long! Assuming you got that number correct, it is in fact quite small, probably because you are using QNX. On a normal desktop system, it is much larger. Here's what I get on fedora 20: > set | wc --bytes 133195 133 kB. I did not count the entries as many of them are sourced functions (git seems to ...


1

Yes. The POSIX specification requires the OS to set a value for $HOME: HOME The system shall initialize this variable at the time of login to be a pathname of the user's home directory. See pwd.h. What about user nobody? # su - nobody No directory, logging in with HOME=/ $ echo $HOME / Even though nobody has no true home, HOME is ...


1

Having a different point of view (from FreeBSD), you have: From man env: The env utility executes another utility after modifying the environment as specified on the command line. Each name=value option specifies the setting of an environment variable, name, with a value of value. All such environment variables are set before the utility is executed. ...


1

From man-pages: env - run a program in a modified environment ... printenv - print all or part of environment Should be pretty explanatory.


4

The output from the locale command is not a list of environment variables from the current environment. It is a display of that process' effective locale settings (which is influenced in part by certain environment variables) and is presented in the same key=value format that the env command uses. You can see the source for the eglibc locale command ...


7

The primary issue here -- which accounts for why, e.g., $PS1 is not reported by env -- is that env is reporting from a non-interactive environment. Processes are executed from a fork of your interactive shell, but there's a subtlety involved in how their environment is set: It's actually inherited via a native C level external variable set for all exec()'d ...


4

The shell knows two types of variables: "internal" variables which are known to the shell only (and to subshells) exported variables, the "official" ones which are seen by execve and thus by env. The shell builtin export shows you the exported variables. If you execute export PS1 and repeat env | grep "PS1" then you see it. Variables can be ...


3

Edit your /etc/cron.daily/0logwatch script, and add the export DATE_MANIP=DM5 before the logwatch call. example: #!/bin/sh #Set logwatch location LOGWATCH_SCRIPT="/usr/sbin/logwatch" #Add options to this line. Most options should be defined in /etc/logwatch/conf/logwatch.conf, #but some are only for the nightly cronrun such as --output mail and should be ...


0

look into BASH_ENV http://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/ try checking out http://stackoverflow.com/questions/6063618/bash-env-or-sourcing-a-file-in-a-non-interactive-non-login-shell


4

Shell variables are initialised from environment variables in every shell, you can't get around that. When the shell starts, for every environment variable it receives that has a valid name as a shell variable, the shell assigns the corresponding shell variable the corresponding value. For instance, if your script is started as: env VAR_A=xxx your-script ...


1

tl;dr: grep -zoP '^VAR_A=\K(?s).*' "/proc/$PPID/environ" It is not entirely clear what you are asking as a "local env variable" is a contradiction. Environment variables are global, not local. You have three types of variables: exported global variables (environment variables). global variables. local variables. Global variables are scoped to the ...


2

You could make the variable VAR_A read only by adding a line: readonly VAR_A at the top of your script. This would cause the value of VAR_A to be preserved as per your local environment. readonly: readonly [-aAf] [name[=value] ...] or readonly -p Mark shell variables as unchangeable. Mark each NAME as read-only; the values of these NAMEs may not be ...


1

If you want to print local variable VAR_A, you must call in its local scope, otherwise, it will print value of global variable VAR_A: #! /bin/bash VAR_A="I'm global" function lexical() { local VAR_A="I'm lexical" echo $VAR_A } echo -n "Global VAR_A: " echo $VAR_A echo -n "Lexical VAR_A: " lexical Run it: $ ./test.sh Global VAR_A: I'm global ...


4

You use Apache environment variable manipulation. So for example: SetEnv db_pass swordfish This can be done in httpd.conf or in .htaccess. You can also set env vars in Rewrite Rules like this: RewriteRule someurl - [E=dbpass:swordfish]



Top 50 recent answers are included