bug-textutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug/compatibility issue with "wc"


From: Steve Long
Subject: Bug/compatibility issue with "wc"
Date: Sat Oct 19 13:04:02 2002

Dear Sir:
   I really like the GNU product and utilities and am porting software from
HPux to Linux.  The "wc" command when issued with an option to request just
one count of output, such as "wc -l" for line count, is usually being used
to set a variable for use a shell script.  Having a leading space returned
by "wc" causes a lot of existing scripts to stop working.  All of these
problems can be easily corrected with changes to the scripts, but to make
porting easier and speed up the movement to Linux it would be better to
remove the leading space.
  The following is an example of this problem:

                        recCntSplit=`cat SrcFile|awk -f awk_split_rec|wc -l`
                        cat splitCtlFile|awk -v vcnt=${recCntSplit} -f
awk_chg_split  >outfile

This script stops functioning on Linux because of the leading space now
returned by the GNU "wc -l" command.  The leading space causes the awk to
fail in the second line of the script because after substitution the second
line reads as follows:

                        cat splitCtlFile|awk -v vcnt= 21 -f awk_chg_split
>outfile

Without adding quotes, awk will try to open an input file and not set the
variable vcnt to 21.

   The easiest way for me to fix this problem in the numerous exiting
scripts was to change each use of " wc -l " to pipe the output through "bc"
which strips the leading space.  I did this by globally replacing " wc -l  "
with " wc -l | bc  ".   In my case this was much easier than adding your
environment variable for POSIX compliance.  

   I do not believe there is any reason to output the leading space when
only one count is to be returned by "wc" and doing so breaks a lot of
existing scripts.  To aid others in porting existing systems to Linux please
remove the leading space when only one count is to be returned by "wc".

Thanks for your consideration of this matter.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]