cli help overloading

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#21 Post by amigo »

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.

learnhow2code

#22 Post by learnhow2code »

amigo wrote:Every shell is unique in regard to which features/syntax they incorporate.
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.

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 compatibility is wanted on un-known systems, then regular POSIX-compliant syntax should be used.
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 you want to use features available in bash, then the shebang should call bin/bash specifically -not /bin/sh.
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.

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.

ebisu
Posts: 176
Joined: Wed 25 Sep 2013, 05:06

#23 Post by ebisu »

learnhow2code wrote:nonetheless, with regards to bash, [ is a binary
Did you try amigo's suggestion?

Code: Select all

# type [
[ is a shell builtin
# type [[
[[ is a shell keyword
What output do you get from the type command?

learnhow2code

#24 Post by learnhow2code »

ebisu wrote:What output do you get from the type command?
son-of-a...

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.

Post Reply