Tag Info

Hot answers tagged

17

First of all, remove that line from your .bashrc. The way to do this in not by playing with $HOME, that variable will always point to your home directory and you don't want to change that just so your shells start in a different place. I'm sure there will be a more elegant way to do this but as a temporary workaround you can simply add this line to your ...


10

The solution is to get the shell to substitute the color variables when defining the prompt, but not the functions. To do this, use the double quotes as you had originally tried, but escape the commands so they aren't evaluated until the prompt is drawn. PS1="\u@\h:\w${YELLOW}\$(virtual_env)${GREEN}\$(git_branch)${RESET}$ " Notice the \ before the $() on ...


7

The paths in $PATH are searched in order. This allows you to override a system default with: export PATH=$HOME/bin:$PATH $HOME/bin is now the first (highest priority) path. You did it the other way around, making it the last (lowest priority) path. When the shell goes looking, it uses the first match it finds. In case it's not clear, this all works by ...


6

When you run a script it gets its own shell and its own environment, which disappears again as soon as the script is finished. To keep the environment variables around, source the script into your shell: $ source a.sh Then the definitions will be put into your current shell's environment and be inherited by any programs you launch from it.


4

The terminal will start in the working directory it inherits from its parent. However, some allow to override it via configuration settings. With gnome-terminal, you can edit your profile, tick run a custom command instead of my shell and make it: sh -c 'cd ~/Documents; exec "${SHELL:-sh}"'


4

At the top of the activate script it says you have to source it and that you cannot run it directly. What it does, is changing some things in the session of bash into which the file is sourced. In your case that bash is the bash that is invoked by running the venv_python3.sh script, not the bash you are typing into interactively. What you could do is make ...


3

The problem is that your variable GREEN contains the literal string consisting of "backslash bracket backslash zero three three" and so on. It does not contain for example an ASCII escape character as required to get your terminal to change colour. You could put control characters into GREEN (and YELLOW and RESET) manually, but a much better option is to ...


2

If you're already counting on the body of f executing in the same shell as the caller, and thus being able to modify variables like a and b, why not make the function just set c as well? In other words: $ function f () { a=3; b=4 ; c=$(echo "$(date): $a $b"); } $ a=0; b=0; f; echo $a; echo $b; echo $c 3 4 Mon Jun 30 14:32:00 EDT 2014: 3 4 One possible ...


2

If you're using Bash 4 or later, you can use coprocesses: function f () { a=3; b=4 ; echo "`date`: $a $b"; } coproc cat f >&${COPROC[1]} exec {COPROC[1]}>&- read c <&${COPROC[0]} echo a $a echo b $b echo c $c will output a 3 b 4 c Sun Jun 29 10:08:15 NZST 2014: 3 4 coproc creates a new process running a given command (here, cat). ...


2

And just to confuse things more, if you log on remotely using SSH your SSH client is to allowed to override (some of) the system defaults with your client side settings/preferences... This is governed by the AcceptEnv directives in the sshd_config file e.g. : # Accept locale-related environment variables AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME ...


2

Given the file you show, you should be able to do: (set -f ; IFS=' ' ; env - $(cat /path/to/file) /path/to/your/program ) If it doesn't work then it is only because you need to format your environment file first. Here's an example: (set -f ; IFS=' ' ; env - $(cat) printenv ) <<\ENV variable1=value1 variable2=value2 variable3=value3 an$d s'om\e ...


1

Another way would be to read the file into an array, and then use the array as an argument. The advantage compared to using process substitution is that it can handle values with whitespace in them. Example: $ cat file FOO=bar X=12 var=a b c $ IFS=$'\n' read -d '' -ra vars < file $ env -i "${vars[@]}" python env.py {'var': 'a b c', 'X': '12', 'FOO': ...


1

You can do it all in Python: $ cat config.py env = { 'FOO' : 'bar', 'X' : '12', } $ cat test.py import os import config os.environ.clear() os.environ.update(config.env) print os.environ Then: $ python test.py {'X': '12', 'FOO': 'bar'}


1

Change the way you fill $GREEN, $YELLOW and $RESET: GREEN="$(echo -e "\033[32m")" YELLOW="$(echo -e "\033[33m")" RESET="$(echo -e "\033[0m")" PS1='\u@\h:\w${YELLOW}$(virtual_env)${GREEN}$(git_branch)${RESET}$ '


1

To restore your /etc/bash.bashrc to its original state (if you can't remember what that is), you can do: sudo rm /etc/bash.bashrc sudo apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall bash Otherwise @aprad046's answer seems like the best solution.


1

Try restoring bash.bashrc to its default setting, and edit your local copy of PATH in your ~/.bashrc file instead. In other words, put those last two lines: export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_60/bin/ export JAVA_HOME=$JAVA_HOME:/usr/lib/jvm/jdk1.7.0_60/bin/java/ in your ~/.bashrc file instead of /etc/bash.bashrc. You might have to restart for changes ...


1

Just assign all of the variables and write the output at the same time. f() { c= ; echo "${c:=$(date): $((a=3)) $((b=4))}" ; } Now if you do: f ; echo "$a $b $c" Your output is: Tue Jul 1 04:58:17 PDT 2014: 3 4 3 4 Tue Jul 1 04:58:17 PDT 2014: 3 4 Note that this is fully POSIX portable code. I initially set c= to the '' null string because ...


1

It’s a kluge, but try f > c.file c=$(cat c.file) (and, optionally, rm c.file).



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