bug-bash
[Top][All Lists]
Advanced

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

built-in '[' and '/usr/bin/[' yield different results


From: Service
Subject: built-in '[' and '/usr/bin/[' yield different results
Date: Tue, 13 Nov 2018 17:29:42 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -fdebug-prefix-map=/build/bash-vEMnMR/bash-4.4.18=. -fstack-protector-strong -Wformat -Werror=format-security -Wall -Wno-parentheses -Wno-format-security uname output: Linux COOL4 4.4.0-17134-Microsoft #345-Microsoft Wed Sep 19 17:47:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.4
Patch Level: 19
Release Status: release

Description:
    It seems that the built-in 'test' does not work properly when run in a sub-shell.

Repeat-By:
    Under Windows 10, WSL.
    Start "bash", terminal with shell pops up.

    1. This works when typed directly:

    # make everything explicit
    export PATH=""
    # ensure that file1 exists and that file2 does not exist
    /bin/touch file1
    /bin/rm -f file2
    # built-in
    if          [ file1 -nt file2 ]; then echo nt; else echo not_nt; fi
    # external
    if /usr/bin/[ file1 -nt file2 ]; then echo nt; else echo not_nt; fi

    # Output is as expected:
    nt
    nt

    2. This does not work:

    # Put the above commands into a script, say check.sh
    # Run with: /bin/sh < check.sh
    # Or      : /bin/sh ./check.sh
    # Or      : /usr/bin/env ./check.sh

    # Output is always not ok:
    not_nt
    nt




reply via email to

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