GNU bug report logs - #59819
Bug Report: [coreutils] echo command interprets wildcards, when read with the 'cat' command from a file, in a for-in loop

Previous Next

Package: coreutils;

Reported by: th3_d0ctor <th3d0ctor <at> gmx.de>

Date: Sun, 4 Dec 2022 16:54:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 59819 in the body.
You can then email your comments to 59819 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#59819; Package coreutils. (Sun, 04 Dec 2022 16:54:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to th3_d0ctor <th3d0ctor <at> gmx.de>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sun, 04 Dec 2022 16:54:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: th3_d0ctor <th3d0ctor <at> gmx.de>
To: bug-coreutils <at> gnu.org
Subject: Bug Report:  [coreutils] echo command interprets wildcards, when
 read with the 'cat' command from a file, in a for-in loop
Date: Sun, 4 Dec 2022 17:24:33 +0100
[Message part 1 (text/plain, inline)]
Dear Debian Team,

i hit a bug in the echo command (coreutils).

The echo command recently started to interpret wildcards, when read
from a file, via "cat" in a for loop.

It has been noticed in the results, after processing textfiles with a
for-loop.
There are occurences of filenames of my hardrive, in the resulting
textfile, when I joined some files via "cat" and some "egrep"
filters.
So i tried to reproduce the issue and i found the cause.

I cannot reproduce this bug, out of a for-loop. But this
particular behavior can be reproduced to 100% under
similar circumstances. To use a absolute path in echo command
"/usr/bin/echo" and "/bin/echo" didn't change the outcome.


Screenshots are attached.


--------------------
Steps To Reproduce /
------------------

works like expected:

$ echo * ==> list current working directory
$ echo "*" ==> prints a '*'
$ var='*'; echo "$var" ==> prints a '*'
$ echo '*' >file; cat file ==> prints a '*'
$ echo '*' >file; a=`cat file`; echo "$a" ==> either print a '*'


fails:

$ echo "*" >b; for i in `cat b`; do echo "$i"; done
==> list current working directory instead of printing the wildcard '*'

----------

Same behavior I found with other wildcards, like '?'.

Strangely this command don't show any result - just a empty line:
$ while read i; do echo "$i"; done <<textfile_with_wildcard_in_it>


Whilst following command the exact desired result, of printing the
wildcard:
$ while read i; do echo "$i"; done <<<`cat <textfile_with_wildcard_in>`




Additional Information
---------------------------------------------------------------------------------------------------------------
Linux m0b1 5.18.0-kali7-amd64 0000001 SMP PREEMPT_DYNAMIC Debian
5.18.16-1kali1 (2022-08-31) x86_64 GNU/Linux

PRETTY_NAME="Kali GNU/Linux Rolling"
NAME="Kali GNU/Linux"
VERSION="2022.4"
VERSION_ID="2022.4"
VERSION_CODENAME="kali-rolling"

Package: coreutils
Essential: yes
Status: install ok installed
Priority: required
Section: utils
Installed-Size: 18062
Maintainer: Michael Stone <mstone <at> debian.org>
Architecture: amd64
Multi-Arch: foreign
Version: 9.1-1



$ which echo
/usr/bin/echo

$ file
/usr/bin/echo /usr/bin/echo: ELF 64-bit LSB pie executable, x86-64,
version 1 (SYSV), dynamically linked, interpreter
/lib64/ld-linux-x86-64.so.2,
BuildID[sha1]=a18e44e70d0bf293fabf3685eb1b75bd89fa6663, for GNU/Linux
3.2.0, stripped

$ file /bin/echo
/bin/echo: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,
BuildID[sha1]=a18e44e70d0bf293fabf3685eb1b75bd89fa6663, for GNU/Linux
3.2.0, stripped
---------------------------------------------------------------------------------------------------------------

I hope this help to locate the issue.
If you need additional information, you are welcome to ask.

Kind regards and keep on your good work.

Greetings,
m4tt
[Screenshot from 2022-12-04 11-46-51.png (image/png, attachment)]
[Screenshot from 2022-12-04 11-12-28.png (image/png, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#59819; Package coreutils. (Sun, 04 Dec 2022 17:56:01 GMT) Full text and rfc822 format available.

Message #8 received at 59819 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: th3_d0ctor <th3d0ctor <at> gmx.de>
Cc: 59819 <at> debbugs.gnu.org
Subject: Re: bug#59819: Bug Report: [coreutils] echo command interprets
 wildcards, when read with the 'cat' command from a file, in a for-in loop
Date: Sun, 04 Dec 2022 18:55:07 +0100
On Dez 04 2022, th3_d0ctor wrote:

> $ echo "*" >b; for i in `cat b`; do echo "$i"; done
> ==> list current working directory instead of printing the wildcard '*'

That's how it is supposed to work, since file name expansion is
performed after all other expansions (just before quote removal).

This is basic shell operation knowledge that everyone using the shell
should remember.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."




Information forwarded to bug-coreutils <at> gnu.org:
bug#59819; Package coreutils. (Sun, 04 Dec 2022 23:18:03 GMT) Full text and rfc822 format available.

Message #11 received at 59819 <at> debbugs.gnu.org (full text, mbox):

From: th3_d0ctor <th3d0ctor <at> gmx.de>
To: 59819 <at> debbugs.gnu.org
Subject: Re: bug#59819: Acknowledgement (Bug Report:  [coreutils] echo
 command interprets wildcards, when read with the 'cat' command from a file,
 in a for-in loop)
Date: Sun, 4 Dec 2022 22:33:47 +0100
I missed the quote.
Sorry for my bad.

Kind regards



Am Sun, 04 Dec 2022 16:54:02 +0000
schrieb help-debbugs <at> gnu.org (GNU bug Tracking System):

> Thank you for filing a new bug report with debbugs.gnu.org.
>
> This is an automatically generated reply to let you know your message
> has been received.
>
> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.
>
> Your message has been sent to the package maintainer(s):
>  bug-coreutils <at> gnu.org
>
> If you wish to submit further information on this problem, please
> send it to 59819 <at> debbugs.gnu.org.
>
> Please do not send mail to help-debbugs <at> gnu.org unless you wish
> to report a problem with the Bug-tracking system.
>





bug closed, send any further explanations to 59819 <at> debbugs.gnu.org and th3_d0ctor <th3d0ctor <at> gmx.de> Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Tue, 06 Dec 2022 02:14:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 03 Jan 2023 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 167 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.