Hot answers tagged

7

$! is the PID of the most recent background command. See this excellent answer for other special parameters.


6

The shell checks for new mail after a command finished and $MAILCHECK or 600 seconds have passed. echo $! prints the PID of the last background process. After that, a check for mail may happen.


5

$! is replaced by the process identifier of the last process placed in the background in the current shell, if any. The bash manual provides details of all such special parameters. To see this in action: echo $! should print 0 (assuming no jobs have been backgrounded) man bash & echo $! should print the process identifier of the man process which ...


4

You can use eval: $ set -a $ eval "$(command_that_generate_output)" $ set +a $ sh -c 'printf "%s\n" "$DATABASE_URL"' someurl


2

I recommend switching to a systemd based Linux distro, like Fedora or Ubuntu 16.04. systemd can easily pass environment variables to your process AND it can handle automatically restarting your process it fails as well as starting it at boot. Logging is also nicely handled by systemd`s journald. There's also not the overhead of installing or running ...


2

You don't even need env here. In any Bourne-like shell (assuming the file is in sh syntax like in your example): (set -a; . ./e && ruby -e 'p ENV["a"]; p ENV["b"]') (set -a causes all future variable assignments to be exported to the environment). You could also do: cat e - << 'EOF' | paste -sd ' ' - | sh ruby -e 'p ENV["a"]; p ENV["b"]' ...


2

This is an example of not using the right tool for the job. env isn't the only tool that sets environment variables and then chain loads another program. And it doesn't read variable data from file. Of course, the . a.k.a. source command is not the right tool for this job, either. It permits the file to unexpectedly contain shell commands other than ...


1

The source-code (runner.py) does this: term = os.environ.get('TERMCMD', os.environ.get('TERM')) if term not in get_executables(): term = 'x-terminal-emulator' if term not in get_executables(): term = 'xterm' if isinstance(action, str): action = term + ' -e ' + action else: ...


1

Enclose your alias in single quotes instead of double quotes. alias dockereval='eval $(docker-machine env)' Double quotes allow expansion of variable (in bash at least) while single quotes don't


1

In addition to using Environment directive in the systemd service itself as suggested in this answer, another option is the EnvironmentFile directive. Please note that I am no expert in this area (obviously, I am the author of this question); I am only summarizing to the best of my ability the Fedora Wiki. Feel free to edit/correct me. EnvironmentFile ...


1

export PATH=$PATH:/whatever/you/want This will do what you meant :)


1

It is defined in an include-file read by the make program, e.g., by this line at the end of the port makefile: .include <bsd.port.mk> On my FreeBSD 10 system, the include-files are in /usr/ports/Mk, and grep finds these matches: $ fgrep -n PYTHON_REL * bsd.python.mk:70:# PYTHON_REL - Version number in numerical format, to ease bsd.python....


1

Preserves pre existing ENV vars export $(shell [ ! -n "$(ENVFILE)" ] || cat $(ENVFILE) | grep -v \ --perl-regexp '^('$$(env | sed 's/=.*//'g | tr '\n' '|')')\=') test: echo $$FOO To run make ENVFILE=envfile test # bar export FOO=foo make ENVFILE=envfile test # foo


1

After considering other options presented here, and not fully understanding how some of them worked I developed my own path_remove function, which I added to my .bashrc: function path_remove { # Delete path by parts so we can never accidentally remove sub paths PATH=${PATH//":$1:"/":"} # delete any instances in the middle PATH=${PATH/#"$1:"/} # delete ...



Only top voted, non community-wiki answers of a minimum length are eligible