cut (GNU coreutils) 8.24.
echo "TEST=test" | cut -d"=" -f2- outputs
Ttest. I don't think this is the intended behavior.
Am I using it wrong or is there something wrong with my
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The reproduction issues come down to the provider of libc. Namely, it seems like its a bug in uclibc; see: https://bugs.busybox.net/show_bug.cgi?id=4099
Under certain circumstances, cut prints the first character of field 1 and all of field 2 when told to print field 2 -- so for instance:
printf "4123\t2\t3\t4\t5\n" | cut -f 2
prints out 42; not just 2. I did run strace on that cut, and it did show that cut is printing the whole line.
The bug seems related to how it wants to treat lines without delimiters; so a work around for now is using the '-s' flag; like so:
printf "4123\t2\t3\t4\t5\n" | cut -f 2 -s
which prints '2', as expected.
I imagine most people running into this are using buildroot; and I'd recommend modifying uclibc's configuration as per that link. Mainly this just means:
make uclibc-menuconfig Select y for 'String and Stdio Support --> Provide a macro version of [getc|putc]'
note that since this is changing the libc implementation; it is probably prudent to also rebuild basically everything.