Strange behaviour with tail command

You have a problem with Salix? Post here and we'll do what we can to help.
percoco2000
Posts: 8
Joined: 10. May 2023, 07:08

Strange behaviour with tail command

Post by percoco2000 »

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
percoco2000
Posts: 8
Joined: 10. May 2023, 07:08

Re: Strange behaviour with tail command

Post by percoco2000 »

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.
User avatar
gapan
Salix Wizard
Posts: 6238
Joined: 6. Jun 2009, 17:40

Re: Strange behaviour with tail command

Post by gapan »

Hah, nice find. Yes, this looks like a bug in the coreutils package that comes with slackware. I'll investigate further...
Image
Image
User avatar
laprjns
Salix Warrior
Posts: 1105
Joined: 28. Aug 2009, 01:30
Location: Connecticut USA

Re: Strange behaviour with tail command

Post by laprjns »

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?"
percoco2000
Posts: 8
Joined: 10. May 2023, 07:08

Re: Strange behaviour with tail command

Post by percoco2000 »

So in the slackware/salix version the use of -c +XX is invalid? If so, why compiling without the slackbuild generate a working binary?
User avatar
gapan
Salix Wizard
Posts: 6238
Joined: 6. Jun 2009, 17:40

Re: Strange behaviour with tail command

Post by gapan »

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.
Image
Image
User avatar
gapan
Salix Wizard
Posts: 6238
Joined: 6. Jun 2009, 17:40

Re: Strange behaviour with tail command

Post by gapan »

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:

Code: Select all

export _POSIX2_VERSION=200809
The default in Slackware is "199209", with this note in the SlackBuild:

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.
You can read more here: https://www.gnu.org/software/coreutils/ ... mance.html
Image
Image
percoco2000
Posts: 8
Joined: 10. May 2023, 07:08

Re: Strange behaviour with tail command

Post by percoco2000 »

So it's not a bug, it's a feature :lol: :lol: :lol:

Thankyou..
percoco2000
Posts: 8
Joined: 10. May 2023, 07:08

Re: Strange behaviour with tail command

Post by percoco2000 »

Was looking this morning at the online help ...

Code: Select all

 -c, --bytes=[+]NUM       output the last NUM bytes; or use -c +NUM to
                             output starting with byte NUM of each file
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 ..... ?????
User avatar
laprjns
Salix Warrior
Posts: 1105
Joined: 28. Aug 2009, 01:30
Location: Connecticut USA

Re: Strange behaviour with tail command

Post by laprjns »

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?"
Post Reply