You need to use 'type' instead of 'which' to find out which is really being used when things are called without a full path.
'type ['
[ is builtin in every shell. [[ is bash-only. I also use [[ almost exclusively because it is more forgiving -especially when comparing to a possibly-null variable.
Many people think that [ is just an alias or clone of 'test' (also builtin!), but this is not so.
Every shell is unique in regard to which features/syntax they incorporate.
If compatibility is wanted on un-known systems, then regular POSIX-compliant syntax should be used. If you want to use features available in bash, then the shebang should call bin/bash specifically -not /bin/sh.
cli help overloading
fair enough, i can appreciate that. i consider "bash" to be the thing im coding for, so i speak of bash as the "standard." but with the additional points youve made, i can appreciate why that may not be the best way to weigh its "truthiness" in this case.amigo wrote:Every shell is unique in regard to which features/syntax they incorporate.
nonetheless, with regards to bash, [ is a binary and [[ is built-in. with busybox, its irrelevant which is builtin because "binaries" are lumped together in one, including the sh or bash interpreter. "built-in" is anything that doesnt have a binary (or alias?)
if i were writing for /bin/sh i would consider that further. as it happens, i write scripts in debian/devuan/refracta and then i do try most of them with puppy tahr before i post them here. if it works in puppy and in debian when pasted into the command line, theyre good.If compatibility is wanted on un-known systems, then regular POSIX-compliant syntax should be used.
when i use a shebang, i use /bin/bash or /usr/bin/env python (or /usr/bin/env python3) ... when i do a one-liner instead of a file, i try it in puppy in urxvt and if it works, its good.If you want to use features available in bash, then the shebang should call bin/bash specifically -not /bin/sh.
but if i were writing system scripts for a distro, i would try to make them work with /bin/sh -- thats the debian standard, and its reasonable.
thank you for pointing out that every shell differs on this.
Did you try amigo's suggestion?learnhow2code wrote:nonetheless, with regards to bash, [ is a binary
Code: Select all
# type [
[ is a shell builtin
# type [[
[[ is a shell keyword
son-of-a...ebisu wrote:What output do you get from the type command?
it said its a "builtin," you cant be blamed for saying that. (it said [[ was a keyword, so theyre still different.)
but id read that its an alias, and it IS in /usr/bin (as a binary.)
since that made no sense at all, i ran mv /usr/bin/[ /root and tried to run [ again (f***er still works.) whoever put the [ binary in /usr/bin is dead to me. it is easily my least favorite command after anything pertaining to systemd.