Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'New Version for both Bash and Tcsh' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
New Version for both Bash and Tcsh
Authored by: ssantry on Apr 02, '04 11:54:58AM

Err, ignore that comment on lines 10 and 11 of the new script. If the script can't determine the shell, it exits right away and doesn't default to bash...



[ Reply to This | # ]
New Version for both Bash and Tcsh
Authored by: Thomas Kaiser on Apr 03, '04 11:46:36AM
Hey folks,

Apple provided us with the "defaults" command to deal with property lists.
So, to read all key/value pairs in a very simple and effective way, you simply need

     defaults read "${HOME}/.MacOSX/environment"

That said, the bash way suitable for 99 percent of all cases to include directly into .bashrc would read as follows (on a single line): defaults read "${HOME}/.MacOSX/environment" | tr -d "{" | tr -d "}" | sed 's{\ =\ {={g' | tr ";" "\n" | grep "=" | while read -r OneLine; do eval export $OneLine; done

Cheers,

Thomas

[ Reply to This | # ]
New Version for both Bash and Tcsh
Authored by: Thomas Kaiser on Apr 03, '04 12:29:47PM
Two small additions:

> the bash way suitable for 99 percent of all cases

That means, this will work unless key or value contain "{", "}", or ";" because they will be converted while parsing the property list.

> tr ";" "n"

Should read "\n". The backslash character "\" has been eaten by the form submission, so once again:
defaults read "${HOME}/.MacOSX/environment" | tr -d "{" | tr -d "}" | sed 's{ = {={g' | tr ";" "\n" | grep "=" | while read -r OneLine; do eval export $OneLine; done


[ Reply to This | # ]