Strange behaviour with tail command
-
- Posts: 8
- Joined: 10. May 2023, 07:08
Strange behaviour with tail command
Hi to everyone... First post on the board.
Developing a bash script, i faced this issue:
The command
echo Mylongstring | tail -c +2 gives me this error:
tail: impossibile aprire '+2' per la lettura: File o directory non esistente
(Transalted : can't open '+2' for reading: File or Directory not exist)
The similar command :]echo Mylongstring | tail -c -2 works.
On my other distro (linux Mint ) both commands works as expected
but on mint i've tail version 8.26, on salix tail version 9.0
Anyt advice? Thanks
Developing a bash script, i faced this issue:
The command
echo Mylongstring | tail -c +2 gives me this error:
tail: impossibile aprire '+2' per la lettura: File o directory non esistente
(Transalted : can't open '+2' for reading: File or Directory not exist)
The similar command :]echo Mylongstring | tail -c -2 works.
On my other distro (linux Mint ) both commands works as expected
but on mint i've tail version 8.26, on salix tail version 9.0
Anyt advice? Thanks
-
- Posts: 8
- Joined: 10. May 2023, 07:08
Re: Strange behaviour with tail command
Found a workaround...
Downloaded coreutils 9.3 + slackbuild from slackware current source tree, compiled but the issue remain, but if compile outside the slackbuild, from a vanilla source, the resulting tail works as expected. So hase to be something related to the patch the slackbuild introduce.
Downloaded coreutils 9.3 + slackbuild from slackware current source tree, compiled but the issue remain, but if compile outside the slackbuild, from a vanilla source, the resulting tail works as expected. So hase to be something related to the patch the slackbuild introduce.
Re: Strange behaviour with tail command
Hah, nice find. Yes, this looks like a bug in the coreutils package that comes with slackware. I'll investigate further...
Re: Strange behaviour with tail command
The long option, --bytes works
Code: Select all
rich[~]$ tail --h
...
Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=[+]NUM output the last NUM bytes; or use -c +NUM to
output starting with byte NUM of each file
Code: Select all
rich[~]$ echo Mylongstring | tail -c +2
tail: cannot open '+2' for reading: No such file or directory
Code: Select all
rich[~]$ echo Mylongstring | tail --bytes=+2
ylongstring
“Don’t you see that the whole aim of Newspeak is to narrow the range of thought?"
-
- Posts: 8
- Joined: 10. May 2023, 07:08
Re: Strange behaviour with tail command
So in the slackware/salix version the use of -c +XX is invalid? If so, why compiling without the slackbuild generate a working binary?
Re: Strange behaviour with tail command
It's probably one of the patches that slackware applies. Probably an unwanted and unnoticed side effect. According to the man page, it should be working. I don't think it's intentional, rather a bug.
Re: Strange behaviour with tail command
Actually, it's not the patches and it's not a bug. It's how the default behavior is for slackware. You can override it with:
The default in Slackware is "199209", with this note in the SlackBuild:
You can read more here: https://www.gnu.org/software/coreutils/ ... mance.html
Code: Select all
export _POSIX2_VERSION=200809
Code: Select all
# Compilation with glibc version later than 2.3.2 needs the environment
# variable DEFAULT_POSIX2_VERSION set to 199209.
# Without that line, the coreutils will start complaining about 'obsolete'
# command switches, like "tail -20" will be considered obsolete.
# This behaviour breaks many other packages... the 'obsolete' parameters are
# too commonly used to disregard them. Better to stick with the older more
# widely accepted standards until things begin to demand the new way.
-
- Posts: 8
- Joined: 10. May 2023, 07:08
Re: Strange behaviour with tail command
So it's not a bug, it's a feature
Thankyou..
Thankyou..
-
- Posts: 8
- Joined: 10. May 2023, 07:08
Re: Strange behaviour with tail command
Was looking this morning at the online help ...
And according to this i understand that :
set NN=3
-c +NN output starting from NN bytes, so mylongstring --> longstring (starting from 3rd bytes)
--bytes=+NN output the last NN bytes, so mylongstring --> ing (the last 3 bytes)
Obviously it does'nt work this way ..... ?????
Code: Select all
-c, --bytes=[+]NUM output the last NUM bytes; or use -c +NUM to
output starting with byte NUM of each file
set NN=3
-c +NN output starting from NN bytes, so mylongstring --> longstring (starting from 3rd bytes)
--bytes=+NN output the last NN bytes, so mylongstring --> ing (the last 3 bytes)
Obviously it does'nt work this way ..... ?????
Re: Strange behaviour with tail command
You get different behaviors with and without the "+"
-c, --bytes=[+]NUM output the last NUM bytes; or use -c +NUM to
output starting with byte NUM of each file
rich[~]$ echo Mylongstring | tail --bytes 3
ng
rich[~]$ echo Mylongstring | tail --bytes +3
longstring
rich[~]$ echo Mylongstring | tail -c 3
ng
rich[~]$ echo Mylongstring | tail -c +3
longstring
“Don’t you see that the whole aim of Newspeak is to narrow the range of thought?"