cannot set PATH on .profile - macos

I am new to the MAC OSX and am trying to set my PATH variable. In my .profile I have the following code
# .profile
echo "hello world"
export PATH=/foo:$PATH
When I launch the terminal, I get:
Last login: Thu Oct 23 20:35:54 on ttys000
hello world
➜ ~ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
The file is executed since I see the echo message. However, the $PATH variable does not change at all. Why is that?
EDIT
I've tried to echo out the PATH variable from the script, as follows:
# .profile
echo "hello world"
export PATH=/foo:$PATH
echo $PATH
Which gives me:
Last login: Thu Oct 23 20:53:14 on ttys000
hello world
/foo:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
➜ ~ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
➜ ~
I don't understand this behavior. The PATH variable is modified while the .profile script is being executed, but resets to the default afterwards. Is that by design or am I doing something wrong here?
Any help would be very appreciated.
EDIT:
Thanks to the comments. I could find the root of the problem: Since I am using zsh, there's also a .zshrc file which is executed after the .profile.

Related

Centos systemctl startup script - Ruby bad interpreter

I'm getting the following error when systemctl attempts to run my startup script
/usr/bin/startup/status_start.sh: /usr/local/bin/procodile: /usr/bin/ruby: bad interpreter: No such file or directory
Here's my start script
#!/usr/bin/bash
cd /opt/staytus/staytus/
procodile start
Now I assume this has something to do with the bash shell and PATH's etc but I don't really understand that world :)
I have tried my start script with both #!/usr/bin/bash and #!/bin/bash
Any other suggestions?
UPDATE 1:
added a line to my script to print out 'which ruby' which resulted in the following error
Oct 06 17:31:02 status.sh[11014]: which: no ruby in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
which lead me to add more
echo "current path:" $PATH
PATH=/opt/staytus/.rbenv/shims/ruby:$PATH
echo "new path:" $PATH
BUT despite my attempts I still get errors when systemctl runs start...
Oct 06 17:45:37 start.sh[2878]: current path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Oct 06 17:45:37 start.sh[2878]: new path: /opt/staytus/.rbenv/shims/ruby:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Oct 06 17:45:37 start.sh[2878]: /usr/bin/startup/start.sh: /usr/local/bin/procodile: /usr/bin/ruby: bad interpreter: No such file or directory
Update 2
here's the systemctl script
[Unit]
Description=Starts up procodile which runs staytus
[Service]
User=staytus
Type=simple
WorkingDirectory=/opt/staytus/staytus/
ExecStart=/usr/bin/startup/start.sh
ExecStop=/usr/bin/startup/stop.sh
# Restart=on-abort
[Install]
WantedBy=multi-user.target
When running version as root, staytus
bash: /usr/bin/ruby: No such file or directory
Ruby appears to be installed in
which ruby
~/.rbenv/shims/ruby
UPDATE 3:
OK so I decided to add what appeared to be missing path flows into my script by another script that prints the command to set the environment via the eval command
path.sh
#!/bin/sh
echo export PATH=/opt/staytus/bin/procodile:/opt/staytus/.rbenv/shims/ruby:/usr/lib64/ruby:/usr/share/ruby:/usr/bin/bash:$PATH
start.sh
#!/usr/bin/env bash
set -xv
whoami
echo "current path:" $PATH
cd /opt/staytus/staytus/
pwd
eval `/usr/bin/startup/path.sh`
echo "New path:" $PATH
procodile start
One of your scripts -- probably /usr/local/bin/procodile, but potentially something it invokes -- starts with #!/usr/bin/ruby.
However, your Ruby interpreter isn't installed as /usr/bin/ruby, so that breaks.
Find the responsible script, and change its first line to #!/usr/bin/env ruby, which will honor the PATH for finding the interpreter to run with.

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

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.

Shared Environment File

I have a need to set environment variables JAVA_HOME, CATALINA_HOME, PATH, and the like. I thought it would be a good idea to set these in a shared file, ~/.setenv, then call it in my ~/.profile:
... code ...
/home/myusername/.setenv
When I log in I see the echos print my JAVA_HOME variable and it is set correctly, but when I then do echo $JAVA_HOME manually it prints nothing.
Why isn't my .setenv script setting my variables?
Here is my .setenv file:
export JAVA_HOME=/usr/local/jdk1.6.0_45
export PATH=$PATH:$JAVA_HOME/bin
export CATALINA_HOME=/var/lib/apache-tomcat-6.0.37
export CATALINA_BASE=/var/lib/apache-tomcat-6.0.37
whoami
echo "JAVA_HOME set to $JAVA_HOME"
echo "CATALINA_HOME set to $CATALINA_HOME"
echo "You can change this in /home/myusername/.setenv"
Output when logging in:
Welcome to Ubuntu 13.04 (GNU/Linux 3.8.0-19-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Thu Jun 13 16:11:21 2013 from 192.168.1.200
o#: command not found
myusername
JAVA_HOME set to /usr/local/jdk1.6.0_45
CATALINA_HOME set to /var/lib/apache-tomcat-6.0.37
You can change this in /home/myusername/.setenv
You need to source the .setenv script so the variable assignments are done in the current shell rather than in a sub-shell. Variable assignments in a sub-shell have no effect on the parent shell.
. /home/myusername/.setenv

MacOSX how to autorun a script after su - root?

Lets assume i am normal user, the i will switch to root:
user ~ $ su - root
Password:
root ~ #
So once i logged in as root, i want to run following command automatically:
source .bash_profile
How can i have that above command run automatically please?
According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
In your case, you don't need to source .bash_profile like this.
You just need to put source .bash_profile in your root's .bashrc file
if [ -f ~/.bash_profile ]; then
source ~/.bash_profile
fi
Read me for better understanding of .bash_profile and .bashrc
Update
Example:
[root#sgeorge-ld ~]# cat .bashrc | tail -1
echo "Testing .bashrc for a stack query"
[root#sgeorge-ld ~]# exit
logout
[sgeorge#sgeorge-ld ~]$ su - root
Password:
Testing .bashrc for a stack query
[root#sgeorge-ld ~]#
First of all, when you switch to root user, you will be still your regular user's home directory. Which .bash_profile you want to execute? /Users/myuser/.bash_profile or root's /var/root/.bash_profile?
Regardless of what you would like to execute, you can edit /var/root/.bashrc (if you don't have it, create one) and add your command there.

-bash no such file or directory, but it exists

I've recompiled vim with the ruby flag for command-T awesomeness, and I wrote a script that will automatically do this for me on any machine I ssh into (and run the script), but an issue that I'm running into is that when I alias the newly compiled vim, bash throws a no such file or directory at me. Here's what I have:
This works fine:
$ alias v="~/Code/vim"
But when I put this same line in my .bashrc, I get:
-bash: =~/Code/vim: No such file or directory
Even funnier, I put this in my .bashrc:
[ -e "~/Code/vim" ] && echo "found it!"
And that prints "found it!"
I'm not sure if it's a permission issue, but I'm just going to put them here anyway:
-rwxr-xr-x 1 buf staff 2374400 Sep 17 16:27 /Users/buf/Code/vim
What am I doing wrong? I'm running mac os x 10.7
-bash: =~/Code/vim: No such file or directory
It looks like you forgot remove the = sign

Resources