Archlinux + MATE Terminal - `.bash_profile` is not being sourced - terminal

I am using Arch Linux with MATE as desktop environment. So terminal emulator is MATE Terminal. Recently I installed Jekyll with gem install jekyll. But when I ran jekyll -v it says bash: jekyll: command not found. So I tried to add path of Jekyll to PATH variable.
I ran PATH=$PATH/$HOME/.gem/ruby/2.2.0/bin and it worked perfectly. Now I can run jekyll commands. To add it permanently to PATH variable I edited the ~/.bash_profile file like following. It is not working after reboot. But
source ~/.bash_profile works perfectly.
#
# ~/.bash_profile
#
[[ -f ~/.bashrc ]] && . ~/.bashrc
export PATH="${PATH}:/home/heisenberg/.gem/ruby/2.2.0/bin"
According to ArchWiki this is the proper way to concat something permanantly to PATH. But it isn't working. Can somebody figure me out where the wrong is?
[N. B. : Adding the same line in ~/.bashrc is doing okay.]

Depending on the option it is given, bash can be run as an interactive shell or login shell. The default interactive shell mode does not read ~/.bash_profile. login shell bash do.
See:
First, some setup:
% cat ~/.bashrc
…
export BASHRC="yes"
…
% cat ~/.bash_profile
…
export BASH_PROFILE="yes"
…
Now run a regular (interactive) bash:
% bash
[galaux#magenta ~]$ echo $BASHRC
yes
[galaux#magenta ~]$ echo $BASH_PROFILE
Notice we did not get yes with this last one.
Now with a login shell:
% bash --login
[galaux#magenta ~]$ echo $BASHRC
yes
[galaux#magenta ~]$ echo $BASH_PROFILE
yes
See paragraph INVOCATION from man bash.

Related

Why does typing $ in fish shell show the error "Unknown command: bind_dollar"?

I am running fishshell 3.5.1 on MacOS Monterey 12.5.1
I can work most all commands just fine but whenever I try to type in the dollar sign (even before pressing Return) I get the error: "Unknown command: bind_dollar"
I've tried:
Reinstalling w/Homebrew
Confirming that fish is in PATH
Deleting my fish.config
Below is the output of my issue and setup:
This happens as soon as I type a dollar sign:
$ fish: Unknown command: bind_dollar
Fish config directory:
~/.config/fish
$ ls
completions/ conf.d/ config.fish fish_variables functions/
Using /bin/sh to examine my $PATH:
$ /bin/sh
sh-3.2$ echo $PATH
/usr/local/bin:/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
Ensuring fish is located in PATH:
sh-3.2$ whereis fish
fish: /usr/local/bin/fish
Viewing the contents of my fish.config (which is the default version):
sh-3.2$ cat config.fish
if status is-interactive
# Commands to run in interactive sessions can go here
end
Thanks to Glenn's comment, I was able to track down the issue:
Running:
grep -r bind_dollar ~/.config/fish
Returned:
~/.config/fish/functions/fish_user_key_bindings.fish
Which contained:
function fish_user_key_bindings
### bang-bang ###
bind ! bind_bang
bind $ bind_dollar # <-- removing this line fixed the issue
### bang-bang ###
end
Removing the "bind_dollar" line fixed the issue.

zsh profile path is not reflected.. in terminal in Mac OS 11.2.3

I have installed mysql, trying to set path.
but somehow it does not reflect.
Is not Mysql compatible for zsh by any chance?
% brew list| grep mysql
mysql#5.7
echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> ~/.bash_profile
% echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
% source ~/.bash_profile
then
% mysql --version
zsh: command not found: mysql
You're using zsh in your terminal, so you need to add export PATH="/usr/local/opt/mysql#5.7/bin:$PATH" into your ~/.zshrc file.
If you don't have that file, do touch ~/.zshrc then add that to your Zsh config file.
Alternatively, if you want to switch back to Bash, just do chsh -s $(which bash) (without sudo to only take effect on current logged-in user) and then restart your shell.

Eval in docker-machine: terminal vs shell script

I'm trying to run a simple shell script to automate changing docker-machine environments. The problem is this, when I run the following command directly in the Mac terminal the following is outputted:
eval $(docker-machine env default)
docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default * digitalocean Running tcp://***.**.***.***:**** v1.12.0
So basically what you would expect, however when I run the following .sh script:
#!/usr/bin/env bash
eval $(docker-machine env default)
The output is:
./run.sh
docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default digitalocean Running tcp://***.**.***.***:**** v1.12.0
So basically, it is not setting it as active and I cannot access it.
Has anyone run into this issue before and knows how to solve it? Seems really strange to me, have got pretty much everything else running and automated apart from this facet.
Cheers, Aaron
I think you need to source your shell script
source ./myscript.sh
as the exports in the eval are being returned to the process you started to run the shell in and then being disposed of. These need to go to the parent e.g. login shell
Consider a.sh
#!/bin/bash
eval $(echo 'export a=123')
export b=234
when run in two ways
$ ./a.sh
$ echo $a
$ echo $b
$ source a.sh
$ echo $a
123
$ echo $b
234
$

How to run .profile inside a shell script in ubuntu

I am running a script which is echoing the environment variables in .profile file and than I am running the script, but I am getting following error
I tried following:
node#node-virtual-machine:~$ cat env.sh
#!/bin/bash
echo 'export JAVA_HOME=/home/node/jdk1.6.0_45' >> /home/node/.profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /home/node/.profile
cd /home/node/
source .profile
node#node-virtual-machine:~$ sh env.sh
sudo: source: command not found
How to execute .profile within a script?
Instead of:
sh env.sh
You should run:
bash ./env.sh
Besides instead of:
source .profile
use:
source ~/.profile
If .profile exists as /home/node/.profile, you have all that is necessary.
Your script says /bin/bash at the top but you run it with sh which is probably dash on your system. You probably are already running Bash at the prompt, so you should say source env.sh instead of sh env.sh if you want the variables to be exposed to your terminal.

IPython Notebook doesn't see environment variables with "bash magic"

I am running IPython Notebook on a vagrant virtual machine, and port-forwarding to my local machine so that I can view the notebook in my web browser. I run a bootstrap script that sets an an environment variable JYTHON_HOME in my /etc/environment with:
sudo echo "JYTHON_HOME=/usr/lib/jvm/jython" | sudo tee -a /etc/environment
source /etc/environment
The boot script later starts up ipython notebook. When I open up the notebook,
%%bash
cat /etc/environment
yeilds
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JYTHON_HOME=/usr/lib/jvm/jython
but
%%bash
echo $JYTHON_HOME
prints an empty line.
I have also tried to append the export line to ~/.profile, /.profile, ~/.bashrc, and etc/profile, all with the same result. I know that the notebook is operating as root, but I can't seem to be able to get it to see my environment variable. What can I include in my boostrapping script that will remedy this?
I needed to actually export the variable in the script itself.
sudo echo "JYTHON_HOME=/usr/lib/jvm/jython" | sudo tee -a /etc/environment
source /etc/environment
export JYTHON_HOME=/usr/lib/jvm/jython

Resources