Ok I inferred incorrectly that bash was also depricating it.
And just because I was curious.
I added the other syntaxes I'm aware of to see how they compared.
looks like [[ -e file && -x file ]], is the quickest.
test_file_1(){
test -f "${1}" -a -x "${1}"
}
test_file_2(){
test -f "${1}" && test -x "${1}"
}
test_file_3(){
[ -f "${1}" -a -x "${1}" ]
}
test_file_4(){
[[ -f "${1}" && -x "${1}" ]]
}
test_file_5(){
[ -f "${1}" ] && [ -x "${1}" ]
}
test_file_6(){
[[ -f "${1}" ]] && [[ -x "${1}" ]]
}
test_case(){
local cnt=${1:?Missing repeat count}
local test_func=${2}
local test_file=${3}
echo "${test_func}" "${test_file}"
time {
while [ $(((cnt -= 1 ) )) != 0 ]; do
"${test_func}" "${test_file}"
done
}
}
: ${TMPDIR:=/tmp}
setup_test(){
touch "${TMPDIR}/file"
touch "${TMPDIR}/exec_file"
chmod a+x "${TMPDIR}/exec_file"
for cFile in "${TMPDIR}/file" "${TMPDIR}/exec_file" ; do
for cTest in test_file_{1,2,3,4,5,6} ; do
time=$(test_case 10000 "${cTest}" "${cFile}" 2>&1)
echo ${time}
done
done
}
./test_bash.sh setup_test
test_file_1 /tmp/file real 0m0.144s user 0m0.132s sys 0m0.008s
test_file_2 /tmp/file real 0m0.146s user 0m0.136s sys 0m0.008s
test_file_3 /tmp/file real 0m0.142s user 0m0.136s sys 0m0.004s
test_file_4 /tmp/file real 0m0.138s user 0m0.120s sys 0m0.016s
test_file_5 /tmp/file real 0m0.172s user 0m0.160s sys 0m0.008s
test_file_6 /tmp/file real 0m0.123s user 0m0.100s sys 0m0.020s
test_file_1 /tmp/exec_file real 0m0.138s user 0m0.116s sys 0m0.020s
test_file_2 /tmp/exec_file real 0m0.151s user 0m0.140s sys 0m0.008s
test_file_3 /tmp/exec_file real 0m0.142s user 0m0.140s sys 0m0.000s
test_file_4 /tmp/exec_file real 0m0.118s user 0m0.112s sys 0m0.004s
test_file_5 /tmp/exec_file real 0m0.162s user 0m0.148s sys 0m0.012s
test_file_6 /tmp/exec_file real 0m0.142s user 0m0.132s sys 0m0.004s
Am 23.08.2017 um 17:17 schrieb Chet Ramey:
On 8/23/17 11:13 AM, dethrophes wrote:
Yhea I just learned that now, it's been at least a decade since I looked at
the posix spec on test.
Should probably update the bash help to reflect that
as help bash (in my version at least) only says
EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
Why update the help documentation? Bash supports it. It's just deprecated
in the posix standard.