Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 17th March 2011, 04:01 PM
James Board Offline
Registered User
 
Join Date: Mar 2008
Posts: 278
linuxopera
Setting PATHs in .cshrc or .login

I'm a csh user. In my .cshrc or .login files, I'd like to add certain directories to my search PATH, but I'd first like to check if those directories are already in the search path before attempting to add them (so don't add the same directory twice). The following isn't working

Code:
if ( "${PATH}" !~ ~/bin ) then
    setenv PATH "${PATH}:$HOME/bin"
endif

The problem is that the if-statements always evaluates to TRUE, meaning that ~/bin is always added to the path, even if it's already in the path.

What am I doing wrong in the above regulat expression, or alternatively, what's an easy way to accomplish the same thing?
Reply With Quote
  #2  
Old 17th March 2011, 05:05 PM
Smoking Tux's Avatar
Smoking Tux Offline
Registered User
 
Join Date: Jan 2011
Location: /home
Posts: 268
linuxchrome
Re: Setting PATHs in .cshrc or .login

As first, a little typo I guess, '!~' instead of '!='. Secondly, your if-command would only work either $PATH is totally empty or contains nothing but '~/bin'.
Just try:
Code:
if ( `echo $PATH | egrep -c '~/bin'` == 0 ) then
    setenv PATH "${PATH}:$HOME/bin"
endif
__________________
regards, Thomas
Reply With Quote
  #3  
Old 18th March 2011, 07:22 PM
James Board Offline
Registered User
 
Join Date: Mar 2008
Posts: 278
linuxopera
Re: Setting PATHs in .cshrc or .login

Thanks. That works. Is there no way to do that in the csh, without running an external shell command?
Reply With Quote
  #4  
Old 18th March 2011, 10:06 PM
Smoking Tux's Avatar
Smoking Tux Offline
Registered User
 
Join Date: Jan 2011
Location: /home
Posts: 268
linuxchrome
Re: Setting PATHs in .cshrc or .login

I must admit that I'm not very familiar with csh. However, I think there is a way. The problem is, as far as I know, that csh isn't able to read from a pipe, so you have to write some lines more to 'ship around'. Just try following:
Code:
set my_paths=/tmp/my_paths
echo $PATH > $my_paths

if  ( { grep -c '~/bin' $my_paths } == 0 ) then
        setenv PATH "${PATH}:$HOME/bin"
endif
__________________
regards, Thomas
Reply With Quote
Reply

Tags
cshrc, login, paths, setting

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
.cshrc deleted ramy.m Using Fedora 0 26th October 2010 05:13 PM
Fedora 11 csh.cshrc xerxesrex EOL (End Of Life) Versions 2 2nd October 2010 12:11 PM
Setting virtual hosts, paths, dns, etc adrianTNT Using Fedora 9 4th February 2009 09:46 PM
setting paths maximal Using Fedora 3 6th March 2005 04:21 AM


Current GMT-time: 09:50 (Wednesday, 19-06-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat