4 ms·
Hardlinks actually, but who's counting? plus in real world usage you will hit the shell builtin anyway. ls -li /bin/\[ /bin/test 26016 -r-xr-xr-x 2 root
by somat 3y ago
Hardlinks actually, but who's counting? plus in real world usage you will hit the shell builtin anyway.
ls -li /bin/\[ /bin/test
26016 -r-xr-xr-x 2 root bin 133256 Mar 25 2023 /bin/[
26016 -r-xr-xr-x 2 root bin 133256 Mar 25 2023 /bin/test
I have to admit I avoid "[" in my scripts, it is a weird hack trying to make a command look like syntax and this really bothers me for some reason.
- yjftsjthsd-h 3y agoNo, Alpine uses symlinks: $ docker run --rm -ti alpine / # ls -l /usr/bin/test /usr/bin/[ lrwxrwxrwx 1 root root 12 Sep 28 11:18 /usr/bin/[ -> /bin/busybox lrwxrwxrwx 1 root root 12 Sep 28 11:18 /usr/bin/test -> /bin/busybox / # ls -li /usr/bin/test /usr/bin/[ 495254 lrwxrwxrwx 1 root root 12 Sep 28 11:18 /usr/bin/[ -> /bin/busybox 495360 lrwxrwxrwx 1 root root 12 Sep 28 11:18 /usr/bin/test -> /bin/busybox / #
- figmert 3y agoThis is different. Alpine uses busybox, where everything is implemented in the busybox binary, thus everything is symlinked to it. In other distributions, test is a separate binary, and [ is a link.
- somat 3y agoInteresting... Doubly so because I thought busybox was a sort of linux crunchgen, A way to pack many independent executables into one to save space. With crunchgen at least, each executable name is then linked to the packed binary, that is, hardlinks. and the filesystem name is used to pick the correct code to run. Why did they go with softlinks? my guess... It can be moved across filesystem boundaries. Perhaps interference from cgroups? http://man.openbsd.org/crunchgen http://man.openbsd.org/crunchgen
- arp242 3y agoBoth just look at the first entry in argv. Whether you used a hard- or symlink isn't very important for that. Or at least, that's how FreeBSD crunchgen works. Maybe they changed that in OpenBSD?
- chatmasta 3y agoWhat bothers me is that you can write equivalent code with `test` and `[`, but when using `[` you need to terminate your conditional expression with `]`. Why? Isn't it the same binary? Why is the shell adding this extraneous requirement, just to surface "syntax errors" rather than simply treating `]` as a no-op?
- kqr 3y agoIt is the test command that requires the terminating ] when it is invoked as [. It's possible your shell pre-empts this requirement and presents it as a proper syntax error, but it would have failed anyway.