Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I was going to mention that it came up just days ago on Unix and Linux StackExchange. (-:

* https://unix.stackexchange.com/a/497561/5132

The conditionally defined shell function in one of the other answers is a more appealing approach, especially given the native behaviours of some shells with respect to variable expansion. But also given that /bin/true is not necessarily the pathname.

    % export BLAH='/bin/true too'
    % dash -c '$BLAH 1 2 3'
    % dash: 1: /bin/true: not found
    % sh -c '$BLAH 1 2 3'
    /bin/true: not found
    % ksh -c '$BLAH 1 2 3'
    ksh: /bin/true: not found
    % zsh -c '$BLAH 1 2 3'
    zsh:1: no such file or directory: /bin/true too
    % bash -c '$BLAH 1 2 3'
    bash: /bin/true: No such file or directory
    % 
    % export BLAH='/usr/bin/true too'
    % zsh -c '$BLAH 1 2 3'
    zsh:1: no such file or directory: /usr/bin/true too
    % bash -c '$BLAH 1 2 3'
    % ksh -c '$BLAH 1 2 3'
    % dash -c '$BLAH 1 2 3'
    %


Yeah, that was my answer -- and actually I wrote /usr/bin/true on SO but got sloppy here.

I wrote that answer because I recalled it as a common idiom in autoconf or something -- some automake system I'd seen where the system seeks out the tools it needs and defines them as variables.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: