public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
* Adding to the PATH but not if already in $PATH
@ 2005-02-26 18:16 Dog Walker
  2005-02-26 22:44 ` chuck gelm
  0 siblings, 1 reply; 6+ messages in thread
From: Dog Walker @ 2005-02-26 18:16 UTC (permalink / raw)
  To: linux-newbie

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?

-
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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Adding to the PATH but not if already in $PATH
@ 2005-02-26 18:17 Dog Walker
  2005-02-26 19:05 ` Eric Bambach
  0 siblings, 1 reply; 6+ messages in thread
From: Dog Walker @ 2005-02-26 18:17 UTC (permalink / raw)
  To: linux-newbie

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?

-
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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Adding to the PATH but not if already in $PATH
  2005-02-26 18:17 Dog Walker
@ 2005-02-26 19:05 ` Eric Bambach
  2005-02-26 19:40   ` DogWalker
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Bambach @ 2005-02-26 19:05 UTC (permalink / raw)
  To: Dog Walker; +Cc: linux-newbie

On Saturday 26 February 2005 12:17 pm, you 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?

sed and grep can help.

echo $PATH | grep 'SOMEPATH'
if [ $? == 0 ];then
 export PATH
else
        PATH=NEWPATH
fi

Check the login on that though, shouldnt be too hard.
> -
> 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

-- 
----------------------------------------
--EB

> All is fine except that I can reliably "oops" it simply by trying to read
> from /proc/apm (e.g. cat /proc/apm).
> oops output and ksymoops-2.3.4 output is attached.
> Is there anything else I can contribute?

The latitude and longtitude of the bios writers current position, and
a ballistic missile.

                --Alan Cox LKML-December 08,2000 

----------------------------------------
-
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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Adding to the PATH but not if already in $PATH
  2005-02-26 19:05 ` Eric Bambach
@ 2005-02-26 19:40   ` DogWalker
  2005-02-26 20:34     ` Eric Bambach
  0 siblings, 1 reply; 6+ messages in thread
From: DogWalker @ 2005-02-26 19:40 UTC (permalink / raw)
  To: linux-newbie

[-- Attachment #1: Type: text/plain, Size: 574 bytes --]

"Eric Bambach" <eric@cisu.net> said:

>On Saturday 26 February 2005 12:17 pm, you 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.
>>
>

[...]

>sed and grep can help.
>
>echo $PATH | grep 'SOMEPATH'
>if [ $? == 0 ];then
> export PATH
>else
>        PATH=NEWPATH
>fi
>
>Check the login on that though, shouldnt be too hard.

Great!

Sorry about the double post: kmail did what I said not what
I meant.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Adding to the PATH but not if already in $PATH
  2005-02-26 19:40   ` DogWalker
@ 2005-02-26 20:34     ` Eric Bambach
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Bambach @ 2005-02-26 20:34 UTC (permalink / raw)
  To: DogWalker; +Cc: linux-newbie

On Saturday 26 February 2005 01:40 pm, you wrote:
> "Eric Bambach" <eric@cisu.net> said:
> >On Saturday 26 February 2005 12:17 pm, you 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.
>
> [...]
>
> >sed and grep can help.
> >
> >echo $PATH | grep 'SOMEPATH'
> >if [ $? == 0 ];then
> > export PATH
> >else
> >        PATH=NEWPATH
> >fi
> >
> >Check the login on that though, shouldnt be too hard.

errr....check the *logic* on that. The syntax is mostly good but treat it as 
pseudocode. I wrote that after I just woke up ;) But I think you got the 
picture.

> Great!
>
> Sorry about the double post: kmail did what I said not what
> I meant.

-- 
----------------------------------------
--EB

> All is fine except that I can reliably "oops" it simply by trying to read
> from /proc/apm (e.g. cat /proc/apm).
> oops output and ksymoops-2.3.4 output is attached.
> Is there anything else I can contribute?

The latitude and longtitude of the bios writers current position, and
a ballistic missile.

                --Alan Cox LKML-December 08,2000 

----------------------------------------
-
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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Adding to the PATH but not if already in $PATH
  2005-02-26 18:16 Adding to the PATH but not if already in $PATH Dog Walker
@ 2005-02-26 22:44 ` chuck gelm
  0 siblings, 0 replies; 6+ messages in thread
From: chuck gelm @ 2005-02-26 22:44 UTC (permalink / raw)
  To: Dog Walker; +Cc: linux-newbie

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-02-26 22:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-26 18:16 Adding to the PATH but not if already in $PATH Dog Walker
2005-02-26 22:44 ` chuck gelm
  -- 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox