[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nmh-workers] Getting the location of the of the nmh executables fro

From: Paul Fox
Subject: Re: [Nmh-workers] Getting the location of the of the nmh executables from a script
Date: Tue, 27 Jan 2015 14:15:09 -0500

ralph wrote:
 > Hi Norm,
 > > Neither 'command -v scan' nor 'which scan' works for me. I want to
 > > name the script, from which I want to know where nmh's scan is
 > > located. "scan". I want to know its location so I can invoke it.
 > OK, so you've your own `scan' script that you want to be found earlier
 > in PATH and have it call the next one that's found if PATH searching
 > continued?  The way I normally do that is to hardcode the path to the
 > next one in line, I must admit.

in bash, i do:
 mhbin=$(type -p install-mh)  # find the install-mh executable
 mhbin=${mhbin%/*}            # strip the last '/' and anything that follows

the first line could be replaced by
        mhbin=`which install-mh`

the second could be replaced by something clever in expr or sed.

later, my script says:
 $mhbin/comp   # run the real 'comp' command


 > PATH could be manipulated to remove the directory that found this scan,
 > so the next one is found.  But that's just as error prone as parsing
 > PATH and searching oneself, remembering that `.' can be an empty
 > element.  The problem is often what is "this" script given it might have
 > been found by searching PATH, or as `../bin/scan'.  bash sets $_ on
 > entry to the script to the absolute path to it, but only if PATH was
 > searched, else it's `../bin/scan', for example.
 > If you don't want to hardcode then how about a script that lists all the
 > places foo is found in PATH;  then you could just pick the second one,
 > assuming the first is the one to skip.  This script lists all places
 > it's found in PATH, if I've done it right, e.g. `searchpath scan'.
 > Piping into `sed -n 2p' would print the second, if there is one.
 >     #! /bin/bash
 >     : ${1?specify command to find}
 >     p="$PATH"
 >     # Make current working directory explicit.
 >     p="${p/#:/.:}"
 >     p="${p/%:/:.}"
 >     p="${p//::/:.:}"
 >     IFS=: read -ra p <<<"$p"
 >     for d in "address@hidden"; do
 >         f="$d/$1"
 >         [[ -r $f && -x $f ]] && printf '%s\n' "$f"
 >     done
 > Cheers, Ralph.
 > _______________________________________________
 > Nmh-workers mailing list
 > address@hidden
 > https://lists.nongnu.org/mailman/listinfo/nmh-workers

 paul fox, address@hidden (arlington, ma, where it's 11.8 degrees)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]