[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: Ralph Corderoy
Subject: Re: [Nmh-workers] Getting the location of the of the nmh executables from a script
Date: Tue, 27 Jan 2015 18:52:10 +0000

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.

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}

    # Make current working directory explicit.

    IFS=: read -ra p <<<"$p"
    for d in "address@hidden"; do
        [[ -r $f && -x $f ]] && printf '%s\n' "$f"

Cheers, Ralph.

reply via email to

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