Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 13, 2010, 07:00 AM   #1
interslice
macrumors member
 
Join Date: Jul 2008
Location: NL
Modify $PATH properly!

I have in my home directory:
.bash_profile < this one has search strings (i recently modified this in text edit)
export JAVA_HOME=/usr/bin
export PATH=/usr/bin:$PATH


.profile < this one tells me instructions about my profile
.bash_login < this one is empty

In Terminal in 2007 I changed my $PATH variable somehow to include "SoyLatte Java 1.6" for Mac Osx 1.4

Now I upgraded to Mac 1.6 snow leaopard - and none of my Java works online

As you can see my .bash profile = 'a normal basic setting'

but when i type into Terminal 'echo $PATH' > i still get this:
/usr/soylatte16-1.0.2/bin:/usr/soylatte16-1.0.2/bin:/bin:/sbin:/usr/bin:/usr/sbin

and I can't change it!

does anyone know how I can get back to my original settings - or how to make the $PATH reflect whats in my .bash profile?

What exactly does the 'echo $PATH' read? it sure as hell doesn't read any of the .bash profile stuff or anything similar! and seems almost impossible to modify ... properly

I also found this code snippet: http://codesnippets.joyent.com/posts/show/1800#related
it looks really useful - does anyone know how to use it?

Thanks
__________________
everything is nothing - our treasure lies in our deepest darkest hole ... FB: SpiritualEggs - everything you need to know!

Last edited by interslice; May 13, 2010 at 12:00 PM. Reason: updated info in my quest to fix the problem
interslice is offline   0 Reply With Quote
Old May 13, 2010, 09:41 AM   #2
pilotError
macrumors 68020
 
pilotError's Avatar
 
Join Date: Apr 2006
Location: Long Island
Did you do the setup in the .profile?

.profile is executed first when sh, bash or ksh is started.

.bash_profile/.bashrc only executes for bash specific shell commands.

You should be able to echo $SHELL to make sure which shell your executing.

you can also do an "ls -al | more" and take a look at all the hidden files that exist and the permissions on them. You need to own the file or have x access in order to run it.

If these files don't exist in $HOME, you may have edited the /etc/profle or /etc/bashrc files, which are like global default files.
pilotError is offline   0 Reply With Quote
Old May 13, 2010, 11:33 AM   #3
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
It seems to me that you are missing underscores in your file names from what you put in your post.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old May 13, 2010, 11:48 AM   #4
interslice
Thread Starter
macrumors member
 
Join Date: Jul 2008
Location: NL
$ echo $SHELL = /bin/bash

ls -al | more =
-rw------- 1 chrisbrown chrisbrown 12445 May 13 18:29 .bash_history
-rw-r--r-- 1 root chrisbrown 101 May 13 16:33 .bash_login
-rw-r--r--@ 1 chrisbrown chrisbrown 132 May 13 14:59 .bash_profile
-rw-r--r-- 1 root chrisbrown 12288 May 13 02:18 .bash_profile.swo
-rw-r--r--@ 1 chrisbrown chrisbrown 799 May 13 13:06 .profile


I don't know much about Mac Terminal editing ...
I don't know if i did the setup in the .profile
What actually physically changes when you edit the path variable?
none of those files in the $HOME directory change!?

I only ever executed the following commands in Terminal ...
sudo vi .bash_login
PATH=/usr/soylatte16-1.0.2/bin:$PATH


This gave me the messy code after a few attempts:
/usr/soylatte16-1.0.2/bin:/usr/soylatte16-1.0.2/bin:/bin:/sbin:/usr/bin:/usr/sbin

I think I just need to delete the soylatte part so I can revert to the normal Java for SnowLeopard!

Thanks for your help - i really appreciate it
__________________
everything is nothing - our treasure lies in our deepest darkest hole ... FB: SpiritualEggs - everything you need to know!
interslice is offline   0 Reply With Quote
Old May 13, 2010, 12:06 PM   #5
interslice
Thread Starter
macrumors member
 
Join Date: Jul 2008
Location: NL
Quote:
Originally Posted by pilotError View Post
Did you do the setup in the .profile?

.profile is executed first when sh, bash or ksh is started.

.bash_profile/.bashrc only executes for bash specific shell commands.

You should be able to echo $SHELL to make sure which shell your executing.

you can also do an "ls -al | more" and take a look at all the hidden files that exist and the permissions on them. You need to own the file or have x access in order to run it.

If these files don't exist in $HOME, you may have edited the /etc/profle or /etc/bashrc files, which are like global default files.
Yes it looks like i have editted the:
etc - profile
# System-wide .profile for sh(1)

PATH="/usr/soylatte16-1.0.2/bin:/bin:/sbin:/usr/bin:/usr/sbin"
export PATH=/usr/soylatte16-1.0.2/bin:$PATH

if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi


can i change this in text edit instead?
__________________
everything is nothing - our treasure lies in our deepest darkest hole ... FB: SpiritualEggs - everything you need to know!
interslice is offline   0 Reply With Quote
Old May 13, 2010, 03:12 PM   #6
pilotError
macrumors 68020
 
pilotError's Avatar
 
Join Date: Apr 2006
Location: Long Island
Quote:
Originally Posted by interslice View Post
can i change this in text edit instead?
I think you have to open the file with admin privs. sudo is easiest, but some text editors allow you to do it by recognizing the permissioning and asking for the password. I'm not sure text edit does that (never tried).
pilotError is offline   0 Reply With Quote
Old May 14, 2010, 06:03 AM   #7
interslice
Thread Starter
macrumors member
 
Join Date: Jul 2008
Location: NL
I think the problem is fixed:
This is really nice but i need a bit more help.

Whenever i used to type ‘echo $PATH’
only ever got back my old PATH – which i found impossible to change
Until now!
I created a .Profile file in my root directory (Mac ??
I copied my text edited file **
Now my echo $PATH reads perfect when I ask Terminal 'echo $PATH'

My questions are:
1.If you don’t have a .profile file in the correct place (what is the correct place? See Q2.)
2.What is the root directory the .profile - .bash_login - .bash_profile files should be in? is it MAC or MAC/users/myname/

3.What are the possible locations that terminal reads and writes to when you type in ‘echo $PATH’ and sudo vi .bash_login (to edit this path)
OR what file is it reading to show you your $PATH!!! (because i was not able to change a file which reflected a change in $PATH in terminal
(i have not found an answer to this question in 2 days of looking in forums)


Now i have .profile files everywhere!!!
I just have big problems understanding what Terminal is editing and showing when you edit the $PATH via the sudo vi .bash_login OR sudo vi .bash_profile (my files were never showing a universally similar PATH)

Some people on several forums think that when you edit the $PATH variable via the sudo vi .bash_profile OR sudo vi .bash_login.
OR where the $PATH is located is in the following places

/usr/share/init/tcsh/login
/etc/rc.common
/etc/csh.cshrc
/etc/profile
/users/myname
/

Why is it so hard for me to understand what Terminal is REALLY showing when you type in echo $PATH
__________________
everything is nothing - our treasure lies in our deepest darkest hole ... FB: SpiritualEggs - everything you need to know!

Last edited by interslice; May 14, 2010 at 06:11 AM. Reason: correction
interslice is offline   0 Reply With Quote
Old May 14, 2010, 07:47 AM   #8
mslide
macrumors 6502a
 
Join Date: Sep 2007
Quote:
Originally Posted by interslice View Post
Why is it so hard for me to understand what Terminal is REALLY showing when you type in echo $PATH
It is simply showing you the current value of the environment variable 'PATH'. That variable can be edited directly on the command line, a shell script you execute yourself or one that is automatically executed when you start up terminal (in more specific terms, when the bash shell is started). If you would like to know exactly what files Bash executes, when starting up, read the bash man page. It tells you in there which ones are read and in what order. If you use a shell other than bash (which you're not unless you changed it), then other files are read and can be found out by reading that shell's man page.

It can also be changed via scripts that are executed when non-login shells are started but that's a more advanced topic (read about login vs non-login shells if you are curious).

Code:
man bash
If you need to edit your path, only edit the files in your home directory unless you have a good reason to edit the system wide ones. Which one you choose to edit can depend on several factors. For your case, almost any of them will work but there are valid reasons to choose one vs the other (i.e. .profile vs .bash_profile vs .bashrc).

Quote:
Originally Posted by interslice View Post
/usr/share/init/tcsh/login
/etc/rc.common
/etc/csh.cshrc
/etc/profile
/users/myname
/
Those files may or may not be read by other shells and/or on different operating systems. Again, the real answer as to which files are read can be found by reading the man page (on your actual computer).

Last edited by mslide; May 14, 2010 at 07:58 AM.
mslide is offline   0 Reply With Quote
Old May 14, 2010, 09:25 AM   #9
pilotError
macrumors 68020
 
pilotError's Avatar
 
Join Date: Apr 2006
Location: Long Island
Quote:
Originally Posted by interslice View Post
I think the problem is fixed:
This is really nice but i need a bit more help.

Whenever i used to type ‘echo $PATH’
only ever got back my old PATH – which i found impossible to change
Until now!
I created a .Profile file in my root directory (Mac ??
I copied my text edited file **
Now my echo $PATH reads perfect when I ask Terminal 'echo $PATH'

My questions are:
1.If you don’t have a .profile file in the correct place (what is the correct place? See Q2.)
When your account is created, you are assigned a home directory for that account. It is typically /Users/<account name>.

You can see your accounts root directory by typing "echo $HOME"

Quote:
2.What is the root directory the .profile - .bash_login - .bash_profile files should be in? is it MAC or MAC/users/myname/
/Users/myname or whatever the $HOME variable equates to

Quote:
3.What are the possible locations that terminal reads and writes to when you type in ‘echo $PATH’ and sudo vi .bash_login (to edit this path)
OR what file is it reading to show you your $PATH!!! (because i was not able to change a file which reflected a change in $PATH in terminal
(i have not found an answer to this question in 2 days of looking in forums)
Re-read my post from above. Basically when you setup your account, you tell the system what your default shell is. In OS X, the default is bash and there really isn't any reason to change it.

When you start terminal, the system knows you want a bash shell, so it actually launches the bash shell for you.

You can verify this by typing in "ps" at the command prompt. You should see:


PID TTY TIME CMD
909 ttys000 0:00.01 login -pf myUserName
913 ttys000 0:00.02 /bin/bash
915 ttys000 0:00.00 ps


Typically, when you modify a global profile, anybody who logs in will get what is contained in those files. Usually, admins put a very small set of things in those files (like the path to basic shell commands, etc).

So every account on the node will get whatever is defined in

/etc/profile

anyone using bash will get what's contained in

/etc/bash_profile
/etc/bashrc

Once the global definitions are executed, it looks in the $HOME variable to find the YOUR root directory and looks for certain files. If they exist, it executes them.

$HOME/.profile - will get executed by sh, bash or ksh shells when they are started.
$HOME/.bash_profile
$HOME/.bashrc

So since you edited both the global and the local .profile, you are seeing
/usr/soylatte16-1.0.2/bin:/usr/soylatte16-1.0.2/bin:/bin:/sbin:/usr/bin:/usr/sbin

You shouldn't really change the global version, but if it's your machine, it doesn't really matter.

In response to your other question, when you make a change, you need to re-login for the change to take effect, or you need to re-execute what you just changed.

So if you edited .profile, you can execute it in the current shell by:
". .profile" (Thats dot<space>.Profile)

Quote:
Now i have .profile files everywhere!!!
I just have big problems understanding what Terminal is editing and showing when you edit the $PATH via the sudo vi .bash_login OR sudo vi .bash_profile (my files were never showing a universally similar PATH)

Some people on several forums think that when you edit the $PATH variable via the sudo vi .bash_profile OR sudo vi .bash_login.
OR where the $PATH is located is in the following places

/usr/share/init/tcsh/login
/etc/rc.common
/etc/csh.cshrc
/etc/profile
/users/myname
/

Why is it so hard for me to understand what Terminal is REALLY showing when you type in echo $PATH
OK, here's what your missing. When bash reads the file, it is done with the file. When you define $PATH in the file, it copies it from the file into memory. You can look at all the definitions with the "set" command.

So, when you echo $PATH, its looking at the memory version always.

If you edit a file, you need to re-execute the file to copy it into memory.

Sometimes you want the definition to remain only for the time this terminal window is open, so you can modify it at the command line and change only the memory version.

ie.

$ export PATH=$PATH:/someTemporaryDirectory

when you close the terminal window, it will dissapear.

So in short, if you define PATH in /etc/profile, everybody on the box gets it

export PATH=/bin /usr/bin /sbin

When you *Modify* it in /Users/myAccount, only you get it

export PATH=$PATH /usr/soylatte16-1.0.2/bin

when you echo $PATH, you will get

/bin /usr/bin /sbin /usr/soylatte16-1.0.2/bin

If you define the same thing in both places, you will get 2 copies of the same directory, which you found out when you modified both global and local profiles with the same PATH definition.

Last edited by pilotError; May 14, 2010 at 09:33 AM. Reason: fix quoting
pilotError is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
What is the best program to modify the voice? hajime Mac Basics and Help 2 Nov 14, 2013 01:13 AM
iPhone: Tweaks that modify applications -LikesMac- Jailbreaks and iOS Hacks 1 Mar 17, 2013 02:12 PM
iPhone: Folderenhancer: modify layout? fridayxiii Jailbreaks and iOS Hacks 2 Feb 20, 2013 02:06 PM
iPhone: who to modify ? Zaino Jailbreaks and iOS Hacks 5 Feb 9, 2013 09:55 AM
Modify Accent Menu - possible? cymad OS X 10.8 Mountain Lion 1 Oct 11, 2012 01:22 PM

Forum Jump

All times are GMT -5. The time now is 03:05 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC