All of lore.kernel.org
 help / color / mirror / Atom feed
From: chuck gelm <chuck@gelm.net>
To: Dog Walker <forestiero@qwest.net>
Cc: linux-newbie@vger.kernel.org
Subject: Re: Adding to the PATH but not if already in $PATH
Date: Sat, 26 Feb 2005 17:44:51 -0500	[thread overview]
Message-ID: <4220FBE3.80005@gelm.net> (raw)
In-Reply-To: <200502261016.28122.forestiero@qwest.net>

Dog Walker wrote:
> I want to prepend a directory to my PATH in my $HOME/.bashrc and export the 
> result. But I only want it to happen once: iow, if a directory I want 
> prepended is already in the PATH, do not prepend it again.
> 
> Something like:
> 
>    if "/home/dw/bin" not in $PATH ; then
>    PATH=/home/dw:$PATH
>    export PATH
>    fi
> 
> The questions are: Is this the way one guards against multiple additions in 
> subshells? Is there a way to check for a substring?
Hi, DW:

-----
#!/bin/sh
#
# file /usr/local/bin/phwb.sh
#
# This prepends "/home/dw/bin/" to $PATH
PATH=/home/dw/bin:$PATH
export PATH
#end
-----

 >touch /home/dw/bin/phwb.sh
 >chmod +x /home/dw/bin/phwb.sh
 > phwb.sh

If there is already a path to /home/dw/bin,
then the 0 byte file /home/bin/dw/phwb is executed.
else: /usr/local/bin/phwb.sh is executed.


HTH, Chuck


-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

  reply	other threads:[~2005-02-26 22:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-26 18:16 Adding to the PATH but not if already in $PATH Dog Walker
2005-02-26 22:44 ` chuck gelm [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-02-26 18:17 Dog Walker
2005-02-26 19:05 ` Eric Bambach
2005-02-26 19:40   ` DogWalker
2005-02-26 20:34     ` Eric Bambach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4220FBE3.80005@gelm.net \
    --to=chuck@gelm.net \
    --cc=forestiero@qwest.net \
    --cc=linux-newbie@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.