Tag Info

New answers tagged

2

Non-interactive shells don't source .bashrc unless manually requested, and moreover, the service likely doesn't invoke shell (unless it has some kind of wrapper script). How to proceed depends on what exactly are you trying to achieve. Services usually have their own config files to modify their behaviour, and environment can also be specified for each ...


2

You could replace $USER with $(whoami) (a command that is built in on almost all Unix systems). As for why $USER isn't set, it's typically set by login. But since you're SSH'ing into the server instead of using an actual interactive shell, the $USER variable is (and several other environment variables are) never set.


0

For non-interactive bash shells, such as bash scripts, the .bashrc file is not sourced. Only interactive bash shells that are not login shells source this file. For more information, you can look at the INVOCATION section of the bash(1) man page. A service typically won't be a descendant of an interactive shell anyway, so that the .bashrc changes won't have ...


0

Try using C4droid-Shell, and use $CC instead of gcc.


0

systemd is not a shell, so it does not support shell-specific substitutions in environment files. Their format is simply KEY=VALUE, with possible empty lines and comments in between. To quote systemd.exec(5): Settings from these files override settings made with Environment=. If the same variable is set twice from these files, the files will be read in ...


5

Option -0/--null was first introduce on 28-10-2009, and release with GNU coreutils version 8.1. If your coreutils is too old, you should upgrade. Or you can use perl: perl -e '$ENV{_}="/usr/bin/env"; print "$_ => $ENV{$_}\0" for keys %ENV' As @Stéphane Chazelas pointed out in his comment, the above approach doesn't include environment strings that ...


3

If you are working with python anyway you could use: import os import sys for k in sorted(os.environ): if k == '_': v = '/usr/bin/env' else: v = os.environ[k] sys.stdout.write("{}={}\0".format(k, v)) to get very similar output compared to env --null.


1

So, combining the answers from @gilles and @bruno-a (and a couple of other sed tricks) I came up with this one-liner, which will remove (every) REMOVE_PART from PATH, regardless of whether it occurs at the beginning, middle or end of PATH PATH=$(REMOVE_PART="/d/Programme/cygwin/bin" sh -c 'echo ":$PATH:" | sed "s@:$REMOVE_PART:@:@g;s@^:\(.*\):\$@\1@"') ...


2

Environment variables aren't supposed to have an empty name, so many utilities don't support them. The env command from GNU coreutils supports setting the environment variable with an empty name but not unsetting it. That's a bug. $ env '=wibble' env |grep wibble =wibble $ env '=wibble' env -u '' env env: cannot unset `': ...


0

You can do: import os for k in os.environ.keys(): print repr(k) del os.eniviron[k] print os.environ os.environ.clear() I am not sure why a direct os.environ.clear() throws the error, I started the above for loop code to see if I could find the key causing the problem. Please not that you have to specify .keys(), just iterating using for k in ...


2

If you use proxy to make internet connection, maybe your system set some environment variable for your user to set the proxy server IP. When you use sudo without -E option, your environment variables are not preserved, so you can't connect to internet, causing add-apt-repository show that error. Checking add-apt-repository source code, you can see: try: ...


0

Try: export LD_LIBRARY_PATH := /usr/local/lib:$(LD_LIBRARY_PATH) install: #Do Install actions See Section 5.3 of the Make manual for an explanation of Bruce's correct assumption on subshells, whivh leads us to this Answer at StackOverflow, which states that all commands should be executed as a one liner. Update Since the one liner did not work, use ...


1

make is almost certainly executing both lines of commands. However, the line export LD_LIBRARY_PATH=$< (or whatever make expands it) gets executed by a shell that's a child process of the make process. When you type echo $LD_LIBRARY_PATH, you get whatever the environment variable LD_LIBRARY_PATH had in it. Your shell didn't execute the "export", a ...


0

environment variables are stored in /etc/profile file so do more /etc/profile and just check for env variables you want and if /etc/profile is not present then lokk for .profile file in your home directory


0

Firstly, great question! The -E switch only shows the environment at the time the process is launched, so any changes would be invisible to this method. Thus if the data is loaded into the environment after launching the process, then it will not be discoverable through this method. However, this is likely not a feasible strategy, IMHO, for reasons ...


2

By default /etc/environment is read as-is, i.e. no parsing / evaluation / interpolation of variable is done. Put another way: it's not meant to be a shell script. That is why the $GRADLE_HOME is literally there in your PATH. You could simply replace the $GRADLE_HOME in your PATH definition with the actual value.


3

To invoke a login shell using sudo just use -i. When command is not specified you'll get a login shell prompt, otherwise you'll get the output of your command. Example (login shell): sudo -i Example (with a specified user): sudo -i -u user Example (with a command): sudo -i -u user whoami Example (print user's $HOME): sudo -i -u user echo \$HOME ...


3

You're giving Bash to much credit. All "login shell" means to Bash is what files are sourced at startup and shutdown. The $HOME variable doesn't figure into it. The Bash docs explain some more what login shell means: https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html#Bash-Startup-Files In fact, Bash doesn't do anything to set $HOME. ...


1

Your node wants to start Chrome (or any browser) and use environment variables to set it out. Just export the variable along with the path pointing to the binary and it should work: export CHROME_BIN=/usr/bin/chromium-browser Now, actually it should just call sensible-browser instead of forcing you to do this.


1

Most Unix systems use PAM. The pam_env module reads a file very much like your .env. On Linux, pam_env reads a system file /etc/environment and a user file ~/.pam_environment. On OS X (and other *BSD, which likewise use OpenPAM), it appears that pam_env only reads the system file, so you can't set variables per user this way, only for all users.


0

Here is my solution: PATH=$(echo -n $PATH | awk -v RS=: -v ORS=: '!x[$0]++' | sed "s/\(.*\).\{1\}/\1/") A nice easy one liner that does not leave a trailing :


9

bash has special syntax for setting environment variables, while fish uses a builtin. I would suggest writing your .env file like so: setenv VAR1 val1 setenv VAR2 val2 and then defining setenv appropriately in the respective shells. In bash (e.g. .bashrc): function setenv() { export "$1=$2"; } . ~/.env In fish (e.g. config.fish): function setenv; set ...



Top 50 recent answers are included