Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rating: Thread Rating: 60 votes, 4.98 average. Display Modes
Old 01-19-2003, 03:42 AM   #121
mnewman
MVP
 
Join Date: Apr 2002
Location: Korat, Thailand
Posts: 2,046
The problem I'm having now is that tcsh doesn't have an "export" command. I'm having trouble figuring out how to make the PATH_SET variable global.

But, at least the script is working if I set the variable from the command line....
__________________
http://www.mgnewman.com/
mnewman is offline   Reply With Quote
Old 01-19-2003, 05:25 AM   #122
pmccann
Major Leaguer
 
Join Date: Jan 2002
Location: Adelaide, South Australia
Posts: 470
"setenv" is what you're searching for:

setenv EDITOR /usr/local/bin/vim

for example.

Cheers,
Paul
pmccann is offline   Reply With Quote
Old 01-19-2003, 06:47 PM   #123
mnewman
MVP
 
Join Date: Apr 2002
Location: Korat, Thailand
Posts: 2,046
Quote:
Originally posted by pmccann
"setenv" is what you're searching for:

Thank you. I was using this, but it kept failing because of a logic error. (I guess I didn't play "Zoombini's" enough!)

Anyway, here's the code that seems to work. I threw in the test for xterm because I was still getting redundant x11r6 paths in xterm. But, they mysteriously went away.... I left the code there for future use.

If I'd known it was going to take so long to write less than a dozen lines of code, I might not have bothered. At least it kept me busy while the tropical storm messed up my long weekend:

Code:
#.setpath
# this file can be sourced by anyhbody who needs to set the path

if ( ! $?PATH_SET ) then

 	setenv PATH_SET true

 	 if ( "$TERM" == "xterm" )  then
 	 	echo ' setting path for xterm'
	  	setenv PATH  :~/bin:/usr/local/bin:/usr/bin:/bin:
/usr/local/sbin:/usr/sbin:sbin:/Developer/Tools
:/usr/x11R6/bin
	else
		echo 'setting path for some other term'
		 setenv PATH  :~/bin:/usr/local/bin:/usr/bin:/bin:
/usr/local/sbin:/usr/sbin:sbin:/Developer/Tools
:/usr/x11R6/bin	
	endif

else

	echo 'path already set'

endif
I've sourced this in my .tcshrc file and it seems to work as expected.
__________________
http://www.mgnewman.com/
mnewman is offline   Reply With Quote
Old 01-19-2003, 07:05 PM   #124
pmccann
Major Leaguer
 
Join Date: Jan 2002
Location: Adelaide, South Australia
Posts: 470
A couple of quick things: firstly, you should kill that leading colon, which will prevent the ~ from being expanded into your home directory. (That is, I don't think it's working as expected at the moment: try "which exe", where "exe" is in your ~/bin directory: it won't be found.

Secondly, and maybe it's a point of style moreso than one of substance, but if you're going to repeat a long and somewhat ugly string of directories letter for letter then set up a variable to hold it once and once only:

MYPATH=~/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin

and so on, and use it in your calls to "setenv"

setenv PATH $MYPATH

(That way you can change it in a single place rah rah...)

Cheers,
Paul
pmccann is offline   Reply With Quote
Old 01-19-2003, 07:51 PM   #125
mnewman
MVP
 
Join Date: Apr 2002
Location: Korat, Thailand
Posts: 2,046
Paul,

Thanks for your thoughts. I'll get rid of the leading colon. I think it snuk in there during a copy/paste.

Although the long path is repeated in the version of the code I posted, I originally thought that I would have to have separate paths set for xterm and non-xterm sessions. Now I think this is not the case, so I'll probably remove the terminal test.

That said, your point about style is right on. Even if only used once, this long and ugly string ought to be set in a variable to make the logic of the code easier to follow.

Thanks again.
__________________
http://www.mgnewman.com/
mnewman is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:33 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.