delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2013/01/02/15:00:53

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL,BAYES_00,KHOP_SPAMHAUS_DROP,KHOP_THREADED,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Andrew DeFaria <Andrew AT DeFaria DOT com>
Subject: Re: adding a folder to my path
Date: Wed, 02 Jan 2013 12:00:12 -0800
Lines: 52
Message-ID: <kc23ka$ga4$1@ger.gmane.org>
References: <50E46BDD DOT 9000603 AT molconn DOT com>
Mime-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/17.0 Thunderbird/17.0
In-Reply-To: <50E46BDD.9000603@molconn.com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 1/2/2013 9:18 AM, LMH wrote:
> I think this is a cygwin question, though it is certainly a general 
> linux question as well. I would like to divide up and organize some of 
> the apps and links in my path directories (such as /usr/local/bin) 
> into sub directories. If I add a folder to /usr/local/bin, that folder 
> is not in my path. Can someone give me the instructions for adding a 
> folder such as /usr/local/bin/ruby_viewer/ to my path?
This is a basic question that is shell specific and all.

What I do is I have a function, called append_to_path:

    append_to_path ()
    {
         component="$1";
         if [ -d "$component" ]; then
             if [ -z "$PATH" ]; then
                 PATH="$component";
             else
                 PATH="$PATH:$component";
             fi;
         fi
    }

It appends to the PATH IFF the component passed in is a directory that 
exists. This allows me to loop through a set of directories knowing that 
only those that exist will end up on the path:

    systemroot=$(cygpath -u $SYSTEMROOT)
    path_dirs="\
       .\
       "$HOME/bin"\
       "/opt/Rational/Clearcase/bin\
       ...
       "/usr/local/bin"\
       ...
       $systemroot/System32\
       $systemroot

    PATH=
    for component in $path_dirs; do
       append_to_path "$component"
    done

This allows me to set my PATH from scratch exactly how I want it. I add 
Unix paths, Solaris paths, HP_UX paths, FreeBSD paths and Windows paths 
to path_dirs. The net result is that I get the right set of paths on 
each of these systems dynamically.

YMMV.
-- 
Andrew DeFaria <http://defaria.com>
This space for rent


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019