mirror of
https://github.com/flatcar/scripts.git
synced 2025-11-27 13:31:56 +01:00
enter_chroot: tweak awk to match POSIX substr requirements
POSIX says that the first arg to substr() counts from 1 which means
that awk implementations interpret a value of 0 in their own special
way. With gawk, it does the logical thing (imo), but with mawk, it
does it by one less.
Example:
echo abc | mawk '{print substr($0, 0, 2)}' -> a
echo abc | gawk '{print substr($0, 0, 2)}' -> ab
echo abc | mawk '{print substr($0, 1, 2)}' -> ab
echo abc | gawk '{print substr($0, 1, 2)}' -> ab
So stick to the POSIX spec and count from 1.
While we're here, using "len" rather than "l" to improve readability.
URL=http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
BUG=chrome-os-partner:6026
TEST=set /usr/bin/awk to mawk; run `cros_sdk --enter -- true`; see everything unmounted
TEST=set /usr/bin/awk to gawk; run `cros_sdk --enter -- true`; see everything unmounted
Change-Id: I48f57d642730a0b3d909079027edf6ebf1bb9459
Reviewed-on: http://gerrit.chromium.org/gerrit/8163
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
e8aec37165
commit
b2e897bf46
@ -382,8 +382,8 @@ function sub_mounts() {
|
||||
# will). As such, we have to unmount in reverse order to cleanly
|
||||
# unmount submounts (think /dev/pts and /dev).
|
||||
mount | \
|
||||
awk -v path="$1" -v l="${#1}" \
|
||||
'(substr($3, 0, l) == path) { print $3 }' | \
|
||||
awk -v path="$1" -v len="${#1}" \
|
||||
'(substr($3, 1, len) == path) { print $3 }' | \
|
||||
tac
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user