Cannot find the file containing $path - path

If I type echo $PATH on my macbook's terminal, this is the output:
/Users/lkloh/Library/Enthought/Canopy_64bit/User/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/lkloh/.rvm/gems/ruby-1.9.3-p448#rails3tutorial2ndEd/bin:/Users/lkloh/.rvm/gems/ruby-1.9.3-p448#global/bin:/Users/lkloh/.rvm/rubies/ruby-1.9.3-p448/bin:/Users/lkloh/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/lkloh/Library/Python/2.7/lib/python/site-packages/pysmo-aimbat-0.1.2/scripts:/usr/local/git/bin:/usr/texbin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin
However, if I do vi .bash_profile, this is what I get, and I can't remove the extra links i see in the path.
# Added by Canopy installer on 2014-05-04
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/lkloh/Library/Enthought/Canopy_64bit/User/bin/activate
I did vi .profile, and it does not exist. I also did .bash_rc, and it does not exist. How can I find the file with the sym links I see in my $PATH variable? I want to delete some of them.

Mac OS X setting of environment variables, at the OS desktop level, is quite obscure. There are several useful links in the "Mac OS X" section of this article: https://support.enthought.com/entries/23665767-How-do-I-set-PYTHONPATH-and-other-environment-variables-for-Canopy-

Related

macOS Catalina: bash → zsh? Where to add new path variables

Ever since the latest macOS update, I've been using zsh as the default shell. However, all my PATH variables are set up in ~/.bash_profile.
~/.zprofile and ~/.zshenv doesn't exist, and ~/.zshrc has no path variables
My question is: where should I actually put my path variables in the future?
Everything seems to work fine (GO Path, Python, Node paths - none of them are in the zsh profile though..)

how do I change default editor for sudo vipw from "vi" to "vim" by tcsh in FreeBSD

When I use command sudo vipw to edit my password file, It's always use vi as editor. I don't like this very much and want to change it to vim.
I already tried:
Add export EDITOR=/usr/local/bin/vim in /etc/profile.
But shell told me "export: Command not found". I thought the reason is export is built-in function only in bash. And I don't want to change my shell.
AddEDITOR=/usr/lcoal/bin/vim in default block of /etc/login.conf
Add setenv EDITOR vim in /root/.cshrc, /.cshrc, ~/.cshrc
All above didn't work at all.
I have google for hours but could not find anything help.
Your /etc/sudoers file doesn't keep your EDITOR environment variable.
I personally have an /etc/sudoers.d/local file, something like
# We don't need to worry about wheel users breaking in to get root access because they already have it.
Defaults:%wheel env_keep+="HOME EDITOR",!set_home,shell_noargs
I'm not sure why this isn't the default, since wheel users have already been given full access. But it's apparently prevailing wisdom to continue hassling them.
Note: If you're using an older /etc/sudoers file that doesn't support an /etc/sudoers.d directory, these lines can be dropped in there... or you could add #includedir /etc/sudoers.d as the last line of your /etc/sudoers file to enable an /etc/sudoers.d directory. Um, yes, the # is a required part of that line, because someone thought it was important for that directive to look like a comment.
Try adding this to the root user /root/.chsrc:
setenv EDITOR vim
or to set it globally to all users using shell tcsh/csh add it in /etc/csh.cshrc
From the man:
A login shell begins by executing commands from the system files /etc/csh.cshrc
and /etc/csh.login. It then executes commands from files in the user's home directory:
first ~/.tcshrc or, if ~/.tcshrc is not found, ~/.cshrc ...
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on startup.
Also verify vim is installed since is not by default, you could try:
pkg install vim-console
setting the EDITOR or VISUAL environment variable is the key.
if you don't want to go to the trouble of modifying config files (which is indeed the long term solution) then you could sudo su - to get to the root prompt and then you could export EDITOR=/usr/bin/vim before running vipw
There is an empty file called .selected_editor in $HOME (/root).
Remove it and the next call to vipw will ask you to select the editor.

How to find the source of $PATH?

I'm using a Centos 7 server. I'm entering the command echo $PATH and trying to figure out where it's getting the path that it's putting out. The path doesn't match what's in my .bash_profile, and there is no .bashrc file. How do I find out where my current $PATH is being sourced from?
The Default values for .bashrc and $PATH are stored in files /etc/bashrc and /etc/profile. These files are used by shell and kernel for setting default values for proper functioning of the server.
I would advise not to change any values here, as it might cause abnormal behavior in the server.

Run script from dock in Mac OS X

I am developing web applications using Ruby on Rails and Sublime Text 3 on OS X 10.8.4. I recently installed the package RubyTest. The tests only work when Sublime is launched using the command
subl
in terminal. Otherwise I get the error message:
/bin/sh: rspec: command not found
I think that's meant to be the case; that's implied in RubyTest's readme file on github.
However I'd like to retain the ability to launch from the dock. Is there a way I can do this?
Unfortunately, OSX applications do not pick up on your $PATH variable set in Terminal. To change the internal PATH settings in Mountain Lion (this method hasn't been tested with previous versions, although it should work), you'll need to edit /etc/launchd.conf:
Make sure you have admin privileges.
Open Terminal or your favorite substitute and see if there's anything in the file /etc/launchd.conf:
cat /etc/launchd.conf
If you get an error like
cat: /etc/launchd.con: No such file or directory
then continue with the next step. If the cat command does display some content, copy it to the clipboard.
Create a new text file with the following content, modified to fit your needs:
setenv PATH /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/Users/YourUserName/bin:/path/to/gems/bin
If the cat command displayed some content in the previous step, paste it into the new file before the setenv PATH command. If it already contains a setenv PATH command, just modify it to add the directories you need, such as /path/to/gems/bin
Save the new file in your home directory (/Users/YourUserName) as launchd.conf.
Go back to Terminal and enter:
sudo mv ~/launchd.conf /etc
to use admin power to move the new file to /etc, replacing anything that was there before. Depending on your previous usage of the sudo command, you may get a short "be careful doing what you're doing" message, but either way you'll need to enter your password. /etc is not directly accessible through the Save dialog unless you're a real power user and know how to get around OSX's file system restrictions.
Reboot your computer
And you should be all set. If you're interested, launchd and launchctl use the csh/tcsh syntax, so you can't use the bash/zsh export PATH=/usr/local/bin:... format.

Default PATH variable set with .bash_profile empty

I remember after a fresh install of os x, when i did a echo $PATH in the terminal, it responded with a blank line. Now after installing some tools over time, the $PATH variable has /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin value although my .bash_profile is blank. I was wondering where this value is being set?
Plausible candidates would be /etc/profile and /etc/bashrc; there's also /etc/paths and /etc/paths.d to look at. You might also need to look at $HOME/.profile and $HOME/.bashrc. There might be some other places that bash looks too.
As of macOS Catalina, Mac defaults the shell to zsh (Z shell). This type of shell uses .zprofile instead of .bash_profile. To check if you are on bash or zsh, run echo $SHELL. If the result is bin/zsh, you are on zsh. In which case edit your ~/.zprofile for env variables.

Resources