Let's say I have the following export in my ~/.bashrc export MODE=vanilla export PATH=/opt/bin/:/usr/bin/  And two scripts in my home cat ~/setup_foo.sh export MODE=foo export PI_NUMBER=4 export PATH=/opt/bin/tool_foo/:$PATH  cat ~/setup_boo.sh export MODE=boo export PI_NUMBER=3 export PATH=/opt/bin/tool_boo:$PATH  The functionality I want to have: $ echo $MODE vanilla echo $PATH /opt/bin/:/usr/bin/  $ &lt;&lt;activate_foo&gt;&gt; echo $MODE foo echo $PATH /opt/bin/tool_foo/:/opt/bin/:/usr/bin/  $ &lt;&lt;activate_boo&gt;&gt; echo $MODE boo echo $PATH /opt/bin/tool_boo:/opt/bin/:/usr/bin/        --- NOTE, NO FOO HERE PRESERVED!  $ &lt;&lt;back_to_normal&gt;&gt; echo $MODE vanialla echo $PATH /opt/bin/:/usr/bin/    --- NO FOO AND BOO HERE!  What sort of tools, packages, bash should I use intsead of &lt;&lt; pseudo commands &gt;&gt; ? If I just call ~/.setup_foo.sh it will overwrite variable, but do not clean up PATH
65040
I accidentally unset all the directories of $PATH while trying to add a new one in ~/.bashrc. I opened a new terminal window as I was editing and now $PATH is empty. I'm worried if I boot from another drive to find the $PATH I won't be able to boot into this drive again.  Basically, what is the default result of echo $PATH?
30864
The /etc/shells says it has zsh installed in /bin/zsh, but also in /usr/bin/zsh.  brgr@envy17:~$ cat /etc/shells  # /etc/shells: valid login shells /bin/sh /bin/dash /bin/bash /bin/rbash /usr/bin/tmux /usr/bin/screen /bin/zsh        &lt;-- /usr/bin/zsh    &lt;--   Now, the  suggests me to use the one from /usr/bin/.  My question is: why? What is the difference between these two and why is bash for example only intalled at one path (/bin/bash)?
21443
Is there any standard that covers the portability of running a command after variable assignment on the same line?  APPLE="cider" echo hi   How portable is something like that? Where will it work and where won't it?   Also: my shell scripts start with #!/bin/sh if that makes any difference.
44552
I have a program that is installed in a custom directory under /opt. To make it easier to run it, I edited my bashrc to add said directory to my path: export PATH=$PATH:/opt/godi/bin:/opt/godi/sbin  This works fine if I want to run the program without sudo. However, if I try to run it with sudo it fails with a &quot;command not found&quot; error. $ sudo godi_console sudo: godi_console: command not found  Inspecting the PATH variable after using sudo reveals that its not including the same PATH I have as a normal user: $ sudo sh # echo $PATH                  /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin  Why is the PATH not the same? Am I doing something wrong? I'm on Debian Jessie, if it makes a difference. One thing I tried was to invoke /opt/godi/sbin/godi_console directly, passing the absolute path to the executable. Unfortunatelly, that didn't help in this particular case because godi_console itself depends on the PATH being correctly set.
74657
In my ~/.bashrc and ~/.profile I have some variables set to some filepaths:  export MY_VAR1="/path/to/somewhere"   In my ~/bin/ (which is added to my PATH) I have a few scripts that rely on those variables being set.  If I run those commands from the terminal, they work as expected.  However, if I try to double click on a script in Nautilus and run it, it runs as if those variables were not set.  Same thing happens if I add one of the scripts to Gnome's "Startup Applications" using the GUI utility or if I add them to the Gnome menu using the "Main Menu" GUI utility.  I would've thought that since I included these variables in my ~/.profile, which is run at login that gnome and nautilus and processes spawned by them would have access to those variables.  Both Gnome and Nautilus are run under my login user. All my scripts in ~/bin have the bash shebang at the top.  I am new to bash scripting, sorry if I am missing something obvious. I am using Debian Wheezy and Gnome3.
95330
Ok. So, I'm used to Ubuntu and CentOS more than redhat, so I'm hoping there's some obvious solution to this that I'm missing.  I've installed Anaconda (Python). I've placed it in:  /opt/anaconda3   I would like for myself and all users to be able to have the following in their paths:  /opt/anaconda3/bin   I have googled around and have gained a lot of conflicting information about how to "properly" accomplish my mission.  Stuff I have tried:   Adding a bash script to /etc/profile.d Editing /etc/profile Editing /etc/bashrc Adding to root bashrc Editing user .bashrc   All edits involved some form of:  PATH=/opt/anaconda3/bin:$PATH   or  export PATH=/opt/anaconda3/bin:$PATH   Option 2 yielded the addition of /opt/anaconda3/bin to the path for multiple users, but after terminal restarts still did not run the commands within bin (i.e. conda install, ipython notebook, etc.)  Any ideas?
48133
I like to use tools like history, script, and asciinema to record and review xterm (i.e. bash/sh) sessions for typical, general administration reasons, and also, sometimes for comprehensive study/revision; as a learning tool.   I thought of setting the default $SHELL as a direct path to said tools and/or commands, like:   /bin/script transcript.log;  /bin/asciinema rec -w0.5 term_log.json;  But these tools typically rely on having a default $SHELL set (i.e. /bin/bash, /bin/sh, /bin/zsh, etc.). Also, I feel like re-defining system variables (i.e. $SHELL, $TERM, etc.) or trying to get it working with config (*.conf) and dot (~/.bashrc / ~/.bash_profile) files is gona be riddled with all kinds of holes and potential problems. However, every time I decide or realize that I want a transcript of a session, it's after the fact, or I'll be halfway through the interesting part already, or some such scenario.   What's the correct, or best practice to set something like this up to simply log everything (preferably stdin, stdout (and stderr when applicable), etc.) automatically?
41257
Run these commands:  [$] echo 'export VAR="qwertyuiop" export VAR="$VAR:asdf=ghjkl"' &gt; /tmp/vars.sh [$] source /tmp/vars.sh [$] echo $VAR /home/saga/qwertyuiopsdf=ghjkl   As you can see, the variable substitution does not do what we expected. What is the issue here?
84656
I'm wondering if $PATH cascades entries. You'll all need to take a leap of faith with me here, but here it goes.  Let's say we have a Java executable at /usr/bin/java but this version is very old and outdated. Unfortunately, we don't have su access so we can't just replace it. We can, however, download the current version of the JRE/JDK locally and point to the updated version. My question is, how does bash handle the case where we have two or more executables with the same name but in two or more different locations? Does bash somehow choose which one to execute when we type java into the console? Assuming /usr/bin has many other executables that we need, how would the $PATH look for something like this to work correctly?  Ideally, when we type java -version we should see:  java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)   instead of  java version "1.7.0_45" Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) Client VM(build 24.45-b08, mixed mode, sharing)   I'm sure this question has been asked before and has some type of jargon associated with it. I've poked around SE, SO, and some forums but didn't find anything conclusive.
110327
I have separate scripts for tasks in bash. Here is the broken one:  #!/bin/bash PATH=/home/name/ mkdir $PATH cd $PATH &amp;&amp; echo "done." exit 0   Today it broke and first time it simply didn't want to run cd, but created directory. Second time it just said "mkdir command not found." Running this commands exactly with semicolon works fine. What the case?
9673
I am wondering whether there is a general way of passing multiple options to an executable via the shebang line (#!).   I use NixOS, and the first part of the shebang in any script I write is usually /usr/bin/env. The problem I encounter then is that everything that comes after is interpreted as a single file or directory by the system.  Suppose, for example, that I want to write a script to be executed by bash in posix mode. The naive way of writing the shebang would be:  #!/usr/bin/env bash --posix   but trying to execute the resulting script produces the following error:  /usr/bin/env: ‘bash --posix’: No such file or directory   I am aware of , but I was wondering whether there was a more general and cleaner solution.    EDIT: I know that for  scripts, there is a way to achieve what I want, documented in  of the manual:   #!/usr/bin/env sh  exec guile -l fact -e '(@ (fac) main)' -s "$0" "$@"  !#   The trick, here, is that the second line (starting with exec) is interpreted as code by sh but, being in the #! ... !# block, as a comment, and thus ignored, by the Guile interpreter.  Would it not be possible to generalize this method to any interpreter?     Second EDIT: After playing around a little bit, it seems that, for interpreters that can read their input from stdin, the following method would work:  #!/usr/bin/env sh sed '1,2d' "$0" | bash --verbose --posix /dev/stdin; exit;   It's probably not optimal, though, as the sh process lives until the interpreter has finished its job. Any feedback or suggestion would be appreciated.
4103
I have been working on several projects, and they require different environment variables (e.g., PATH for different versions of clang executables, PYTHONPATH for several external modules). Whenever I work on one project, I have to modify these environment variables myself (e.g., change .zshrc/.bashrc and source it); and I sometimes forget and make mistakes.  Is there a way/project that helps do this automatically, similar to what  does in Python?
66951
I have this script:  echo $HOME cd $HOME cd / cd /usr/local/src/   When I run it like this  . script.sh   I get this output:  /home/user : No such file or directory : No such file or directory : No such file or directory   If I run it normally (I added #!/bin/bash before the first line)  sh script.sh   I get this output:  : not found.sh: 2: script.sh /home/user script.sh: 3: Can't cd to /home/user script.sh: 4: Can't cd to / script.sh: 5: Can't cd to /usr/local/src/   The script was run from $HOME directory each time. If I run each command one by one from shell, it executed without problems (invoking cd $HOME from within $HOME simply didn't change directory).  What must I do to make this work?
8916
I'd like to know if there is a way to run  program/shell script without typing full path:  /opt/idea/bin/idea.sh
82072
I want to add to my PATH so that my computer (Ubuntu) knows where to interpret the "R" command (for launching R). I need this so a Terminal or RStudio can find where I installed R.  I did all of the following, none of which permanently associates the command R with the directory of my R installation in ~/R/bin.   export PATH=$PATH:$HOME/R/bin      &lt;- This works within the Terminal session it was enacted in, but if I open up a second terminal, PATH goes back to what it was before I added $HOME/R/bin to it   The same "local Terminal only" behavior occurred when I added this line to two different files, based on recommendations on various websites:   sudo vim ~/.profile   export PATH=$PATH:$HOME/R/bin  sudo vim /etc/environment  export PATH=$PATH:$HOME/R/bin    Why won't R be recognized in new Terminal sessions?
43519
There are several ways to execute a script. The ones I know are: /path/to/script # using the path (absolute or relative) . script        # using the . (dot) source script   # using the `source` command  Are there any other way? What are the differences between them? Are there situations that I must use one and not another?
66311
Possible Duplicate:          I was trying to figure out how to export my environmental via script instead of changing my .bashrc file.   I found  that said:     Variables can only be exported to subordinate processes, you can't   pass them back up to the parent. If you really want your script to   affect the parent shell's environment, run the script as  . ./yourprogram    I just want to know what the difference is between . ./script and ./script?  When I look at it, they booth mean to me, run the script from the current directory?