Bug 165159

Summary: "cat" command within inline script replaces space with newline
Product: [Fedora] Fedora Reporter: Larry Adams <larry.adams>
Component: bashAssignee: Tim Waugh <twaugh>
Status: CLOSED NOTABUG QA Contact: Ben Levenson <benl>
Severity: medium Docs Contact:
Priority: medium    
Version: 4   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-08-04 20:21:11 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Larry Adams 2005-08-04 19:27:58 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050524 Fedora/1.0.4-4 Firefox/1.0.4

Description of problem:
when using "cat" command within inline script, cat replaces spaces in a text line with newline character
[scripts]$ cat test2
alpha beta gamma delta "bingo -" charlie
[scripts]$ for i in `cat test2`
> do
> echo $i
> done
alpha
beta
gamma
delta
"bingo
-"
charlie
[scripts]$ for i in `cat test2`
> do
> echo -n $i
> done
alphabetagammadelta"bingo-"charlie[ap395@ap395-3 scripts]$
[scripts]$ for i in `cat test2`
> do
> echo $i | od -bc -
> done
0000000 141 154 160 150 141 012
          a   l   p   h   a  \n
0000006
0000000 142 145 164 141 012
          b   e   t   a  \n
0000005
0000000 147 141 155 155 141 012
          g   a   m   m   a  \n
0000006
0000000 144 145 154 164 141 012
          d   e   l   t   a  \n
0000006
0000000 042 142 151 156 147 157 012
          "   b   i   n   g   o  \n
0000007
0000000 055 042 012
          -   "  \n
0000003
0000000 143 150 141 162 154 151 145 012
          c   h   a   r   l   i   e  \n
0000010
scripts]$ od -bc test2
0000000 141 154 160 150 141 040 142 145 164 141 040 147 141 155 155 141
          a   l   p   h   a       b   e   t   a       g   a   m   m   a
0000020 040 144 145 154 164 141 040 042 142 151 156 147 157 040 055 042
              d   e   l   t   a       "   b   i   n   g   o       -   "
0000040 040 143 150 141 162 154 151 145 012
              c   h   a   r   l   i   e  \n
0000051
[scripts]$


Version-Release number of selected component (if applicable):
bash-3.0-31

How reproducible:
Always

Steps to Reproduce:
1.create simple line of text words separated by spaces in a file named test2
2.execute following commands against text file test2
3.cat test2
this will show cat works correctly standalone
4. for i in `cat test2`;do echo $i; done
this will show how each word is now broken into a line of its own
5. for i in `cat test2`;do echo -n $i; done
this will show that echo has not printed newline chars which were passed 
to it from cat
6. for i in `cat test2`; do echo $i | od -bc -; done
this will show the octal dump of the echo'd line of text - note octal 012
where spaces were in original text
7. od -bc test2
this will show octal 040 (space char) between words - compare with echo'd 
octal dump of text line in step 6, and see octal 040 replaced with 012
  

Actual Results:  [scripts]$ cat test2
alpha beta gamma delta "bingo -" charlie
[scripts]$ for i in `cat test2`
> do
> echo $i
> done
alpha
beta
gamma
delta
"bingo
-"
charlie
[scripts]$ for i in `cat test2`
> do
> echo -n $i
> done
alphabetagammadelta"bingo-"charlie[ap395@ap395-3 scripts]$
[scripts]$ for i in `cat test2`
> do
> echo $i | od -bc -
> done
0000000 141 154 160 150 141 012
          a   l   p   h   a  \n
0000006
0000000 142 145 164 141 012
          b   e   t   a  \n
0000005
0000000 147 141 155 155 141 012
          g   a   m   m   a  \n
0000006
0000000 144 145 154 164 141 012
          d   e   l   t   a  \n
0000006
0000000 042 142 151 156 147 157 012
          "   b   i   n   g   o  \n
0000007
0000000 055 042 012
          -   "  \n
0000003
0000000 143 150 141 162 154 151 145 012
          c   h   a   r   l   i   e  \n
0000010
scripts]$ od -bc test2
0000000 141 154 160 150 141 040 142 145 164 141 040 147 141 155 155 141
          a   l   p   h   a       b   e   t   a       g   a   m   m   a
0000020 040 144 145 154 164 141 040 042 142 151 156 147 157 040 055 042
              d   e   l   t   a       "   b   i   n   g   o       -   "
0000040 040 143 150 141 162 154 151 145 012
              c   h   a   r   l   i   e  \n
0000051
[scripts]$


Expected Results:  the echo of the cat'd line should have been the same as the cat of the
original text file with no newline characters in it, just spaces between
the words.

Additional info:

Comment 1 Tim Waugh 2005-08-04 20:21:11 UTC
No, you've misunderstood how quoting works.  `cat test2` expands to seven words.