add in the PATH a path if not present in the PATH

add in the PATH a path if not present in the PATH

Post by Gaetan Schnelle » Thu, 03 Aug 2000 04:00:00



I look for a function in POSIX shell. this function must add path in the
$PATH if it isn't present.
by example:
I want add /bin in PATH
echo $PATH
--> /bin:/usr/bin
/bin is in the PATH then i don't add /bin
If I want add /usr/local/bin
/usr/local/bin isn't in the PATH then I add:
PATH=${PATH}:/usr/local/bin

  gaetan.schneller.vcf
< 1K Download
 
 
 

add in the PATH a path if not present in the PATH

Post by Jehs » Thu, 03 Aug 2000 04:00:00



> I look for a function in POSIX shell. this function must add path in the
> $PATH if it isn't present.

function addpath () {
        case $PATH in
                $1:*|*:$1:*|*:$1)
                        # Do nothing
                        ;;
                *)
                        PATH="$PATH:$1"
                        ;;
esac                    

Moshe

--

nullity.dhs.org resnet.gatech.edu burdell.org yo.dhs.org gooning.org



 
 
 

add in the PATH a path if not present in the PATH

Post by Kurt J. Lanz » Thu, 03 Aug 2000 04:00:00



> I look for a function in POSIX shell. this function must add path in the
> $PATH if it isn't present.
> by example:
> I want add /bin in PATH
> echo $PATH
> --> /bin:/usr/bin
> /bin is in the PATH then i don't add /bin
> If I want add /usr/local/bin
> /usr/local/bin isn't in the PATH then I add:
> PATH=${PATH}:/usr/local/bin

for D in <list of directories>
do
        T=`echo $PATH | tr ":" "\n" | grep "^${D}\$"`
        [ "$T" ] || PATH=${PATH}:$D
done
export PATH

Flavor to taste.

 
 
 

add in the PATH a path if not present in the PATH

Post by Jehs » Thu, 03 Aug 2000 04:00:00


[ Superceding old post which contained an error ]


> I look for a function in POSIX shell. this function must add path in the
> $PATH if it isn't present.

function addpath () {
        case $PATH in
                $1:*|*:$1:*|*:$1)
                        # Do nothing
                        ;;
                *)
                        PATH="$PATH:$1"
                        ;;
        esac

Quote:}      

Stick this in your .profile. When you want to add a path, type
addpath /path/to/add

Moshe

--

nullity.dhs.org resnet.gatech.edu burdell.org yo.dhs.org gooning.org


 
 
 

add in the PATH a path if not present in the PATH

Post by Jzho » Thu, 03 Aug 2000 04:00:00


I need to check the files under one directory every day. Is there a
convient way to do this automatically?

Thanks for any help.

 
 
 

add in the PATH a path if not present in the PATH

Post by Jehs » Thu, 03 Aug 2000 04:00:00



> I need to check the files under one directory every day. Is there a
> convient way to do this automatically?

1. Followups should have at least something to do with the post being
   followed-up to.

2. You need to specify your question in much greater detail for us to
   even begin helping you

3. man cron; man crontab

Moshe

--

nullity.dhs.org resnet.gatech.edu burdell.org yo.dhs.org gooning.org


 
 
 

add in the PATH a path if not present in the PATH

Post by Jzho » Thu, 03 Aug 2000 04:00:00


Sorry, I am new here and don't know any rules.

Actually, I want to check the files under one directory to see whether the
files have been changed or any new file has been added each day.

Thanks for your advise.



> > I need to check the files under one directory every day. Is there a
> > convient way to do this automatically?

> 1. Followups should have at least something to do with the post being
>    followed-up to.

> 2. You need to specify your question in much greater detail for us to
>    even begin helping you

> 3. man cron; man crontab

> Moshe

> --

> nullity.dhs.org resnet.gatech.edu burdell.org yo.dhs.org gooning.org



 
 
 

add in the PATH a path if not present in the PATH

Post by mlheu » Thu, 03 Aug 2000 04:00:00



> Sorry, I am new here and don't know any rules.

> Actually, I want to check the files under one directory to see
whether the
> files have been changed or any new file has been added each day.

> Thanks for your advise.



> > > I need to check the files under one directory every day. Is there
a
> > > convient way to do this automatically?

--- snip ---

You would want to look at doing something like

mv ~/dirlist.today ~/dirlist.yesterday
ls /dir/to/search/in > ~/list.today
diff ~/list.today ~/list.yesterday > ~/new_filesf_for_`date`

and put that in your crontab.

Note, you might not be able to cut and paste this, but the algorithm is
there.

--
Marc L'Heureux

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

add in the PATH a path if not present in the PATH

Post by James Frankl » Fri, 04 Aug 2000 04:00:00



>I need to check the files under one directory every day. Is there a
>convient way to do this automatically?

>Thanks for any help.

You would be best served by using cron.  Do a man cron, man 5 crontab, etc....
It is easy to set up, crond is probably already running on your system, and if
your script is already written a simple: crontab -e command can be used to set
up you crontab file.

--
James

 
 
 

add in the PATH a path if not present in the PATH

Post by Ken Pizzi » Fri, 04 Aug 2000 04:00:00



Quote:>    case $PATH in
>            $1:*|*:$1:*|*:$1)
>                    # Do nothing
>                    ;;
>            *)
>                    PATH="$PATH:$1"
>                    ;;
>    esac

You can simplify the "Do nothing" expression by making a small
modification to your case conditional:
        case :$PATH: in
                *:$1:*)
                        # Do nothing
                        ;;
                *)
                        PATH="$PATH:$1"
                        ;;
        esac

Just a thought,
                --Ken Pizzini

 
 
 

add in the PATH a path if not present in the PATH

Post by Jehs » Fri, 04 Aug 2000 04:00:00



> You can simplify the "Do nothing" expression by making a small
> modification to your case conditional:
>    case :$PATH: in

Something I didn't think about :)

Thanks for the suggestion...

Moshe

--

nullity.dhs.org resnet.gatech.edu burdell.org yo.dhs.org gooning.org


 
 
 

add in the PATH a path if not present in the PATH

Post by Gaetan Schnelle » Fri, 04 Aug 2000 04:00:00


Thanks for help.
But if the variable is unknown, I try

function addpath () {
        case :$($1): in
                *:$2:*)
                        # Do nothing
                        ;;
                *)
                        $1="$($1):$2"
                        ;;
        esac

Quote:}

and I type
addpath TOTO /my_path
for add my_path at TOTO

But is not good.

Ken Pizzini a crit :


> >       case $PATH in
> >               $1:*|*:$1:*|*:$1)
> >                       # Do nothing
> >                       ;;
> >               *)
> >                       PATH="$PATH:$1"
> >                       ;;
> >       esac

> You can simplify the "Do nothing" expression by making a small
> modification to your case conditional:
>         case :$PATH: in
>                 *:$1:*)
>                         # Do nothing
>                         ;;
>                 *)
>                         PATH="$PATH:$1"
>                         ;;
>         esac

> Just a thought,
>                 --Ken Pizzini

  gaetan.schneller.vcf
< 1K Download
 
 
 

add in the PATH a path if not present in the PATH

Post by Jehs » Fri, 04 Aug 2000 04:00:00



> Thanks for help.
> But if the variable is unknown, I try
> function addpath () {
>         case :$($1): in
>                 *:$2:*)
>                         # Do nothing
>                         ;;
>                 *)
>                         $1="$($1):$2"
>                         ;;
>         esac
> }
> and I type
> addpath TOTO /my_path
> for add my_path at TOTO
> But is not good.

Um, what are you trying to do? This is nothing like what you appeared
to want to do in your original post. Please explain in more detail what
you are trying to do, and maybe we can help.

The function I wrote for you does exactly what your original post
says. It tkaes in a path, and puts it into the PATH setting if it
doesn't already exist in $PATH.

Moshe

--

nullity.dhs.org resnet.gatech.edu burdell.org yo.dhs.org gooning.org