3 ms·
Not sure why this is being called "Bash" one-liner. It will work with many shells. It will run noticeably faster in Dash, for example. Test it yourself. Linu
by 1vuio0pswjnm7 4y ago
Not sure why this is being called "Bash" one-liner. It will work with many shells. It will run noticeably faster in Dash, for example. Test it yourself. Linux chooses Dash for non-interactive use, like this one-line script, because it is faster than Bash.
- LambdaComplex 4y ago> Linux chooses Dash for non-interactive use That entirely depends on the Linux distro.
- 1vuio0pswjnm7 4y agoSome examples of where one finds Dash (NetBSD-derived Almquist shell, or "ash") in Linux The git.kernel.org repository Slackware Debian Unbuntu Gentoo Arch initramfs Alpine Tiny Core OpenWRT Any other distrib that uses Busybox Android What the OP fails to mention is that this shell one-liner (cf. "Bash one-liner"), as written, requires GNU grep, thanks to "-P". BusyBox grep does not have a "-P" option. In the case of Android, Google uses NetBSD userland programs, e.g., grep, which also does not include PCRE, i.e., "-P". https://coral.googlesource.com/android-core/+/3458bb6ce1d3e73e15075b5962a3662af0af5e04/toolbox/upstream-netbsd/usr.bin/grep/grep.c https://coral.googlesource.com/android-core/+/3458bb6ce1d3e7... https://git.kernel.org/pub/scm/utils/dash/dash.git/ https://git.kernel.org/pub/scm/utils/dash/dash.git/ curl -O https://mirror.rackspace.com/archlinux/iso/2022.10.01/arch/boot/x86_64/initramfs-linux.img xz -dc < initramfs-linux.img|cpio -t|grep -m1 usr/bin/ash
- kps 4y agoIt's written with `-P` but doesn't actually need it. Standard `-E` works just fine instead.
- 1vuio0pswjnm7 4y agoHow many "professional" programmers even know the difference between BRE, ERE and PCRE. Perhaps this is why use of regex is so controversial amongst a majority of "professional" programmers. They are trying to use PCRE for every pattern matching task, i.e, even ones where it is not necessary, whether it is within their programing language or with command-line utilities. This "Bash one-liner" is a simple example. I have reviewed a number of books written about regular expressions and for the most part^1 they focus only on regex as implemented in popular programming languages. That almost invariably is PCRE or some form of PCRE-like pattern matching. There is little distinction, let alone acknowledgment, between PCRE/PCRE-like patterns and anything simpler. Not being a "professional" programmer, I use regex everyday but I never (intentionally) use PCRE.^2 Too complicated for my tastes, not to mention slow if using backtracking. 1. I recall one older book that did include an incomplete table attempting to show which type of regex was used by various UNIX utilities in addition to what regex was used by popular programming languages of the day. 2. For programs that optionally link to a PCRE library, I re-compile without them without it.