Riddle me this Batman! POSIXLY_CORRECT effect on wc

Steven W. Orr steveo at syslang.net
Wed Nov 20 09:48:18 EST 2002


I'm trying to get control of some formating that's supposed to be under 
the control of the environment variable POSIXLY_CORRECT. (I can work 
around it but I want to understand this too.)

663 > wc -l < ~/.bashrc
    195
664 > POSIXLY_CORRECT=1 wc -l < ~/.bashrc
195

So far so good. POSIXLY_CORRECT is needed to eliminate the leading spaces.

665 > foo=$(wc -l < ~/.bashrc)
666 > echo $foo
195

Huh? How does this happen. I expected four leading spaces!

Now try this:

671 > cat ~/xxx.sh 
#! /bin/bash

foo=$(wc -l < ~/.bashrc)
echo "There are $foo lines in bashrc"
POSIXLY_CORRECT=1 foo=$(wc -l < ~/.bashrc)
echo "There are $foo lines in bashrc"

672 > ~/xxx.sh
There are     195 lines in bashrc
There are     195 lines in bashrc
673 > POSIXLY_CORRECT=1 ~/xxx.sh
There are 195 lines in bldmaster
There are 195 lines in bldmaster
674 > 

I'm totally mystified. Can someone *please* explain this one to me? :-(

-- 
-Time flies like the wind. Fruit flies like a banana. Stranger things have -
-happened but none stranger than this. Does your driver's license say Organ
-Donor?Black holes are where God divided by zero. Listen to me! We are all-
-individuals! What if this weren't a hypothetical question? sorr at trebia.com





More information about the gnhlug-discuss mailing list