[Top][All Lists]

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

RE: Bug/compatibility issue with "wc"

From: Steve Long
Subject: RE: Bug/compatibility issue with "wc"
Date: Tue Nov 5 03:42:02 2002

Thank you very much for your reply, I now agree with you.

-----Original Message-----
From: address@hidden [mailto:address@hidden
Sent: Saturday, November 02, 2002 9:45 PM
To: Steve Long
Cc: address@hidden
Subject: Re: Bug/compatibility issue with "wc"

Steve Long <address@hidden> [2002-10-17 14:00:48 -0400]:
>    I really like the GNU product and utilities and am porting software
> HPux to Linux.  The "wc" command when issued with an option to request
> 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.

Printing or not printing a leading space is one of those areas that
every operating system does differently.  HPUX does not print a space.
IBM AIX does print a space.  I lose track of which systems do which.
I think BSD prints a space but am not sure.  But in the end people
either want it one way or the other.  GNU prints with a space because
that is what the majority of users wish to see.  But GNU also gives
you an option by setting POSIXLY_CORRECT so that there is no space.

> 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.

If the command was changed gratuitously then the same possibility
exists to break other scripts in the other direction.

But your scripts were not portable previously.  If you were to run
them on AIX then you would have seen the same problems.  It would
really be a lot better to clean up your scripts so that they are
portable and less sensitive to operating system changes.

>    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
> which strips the leading space.  I did this by globally replacing " wc -l
> with " wc -l | bc  ".

Hmm...  I would not have chosen bc.  I probably would have chosen tr.
Using bc seems a little heavy to me and may produce other output.
Also, may I suggest you can improve your scripts by removing the
redundant 'cat' processes?  They are not needed there.

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

  recCntSplit=$(awk -f awk_split_rec < SrcFile | wc -l | tr -d ' ')
  awk -v vcnt=$recCntSplit -f awk_chg_split < splitCtlFile > outfile

> In my case this was much easier than adding your environment
> variable for POSIX compliance.

I am unconvinced that setting an environment variable is harder than
either rewriting scripts or changing the code.  That was the hole
point of that variable.  Setting the variable should be trivial.

>    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.

Ahem, they only break scripts which were arguably not portable to
begin with.  They do not break any script developed on either GNU or
AIX or any of the other very very many systems where printing spaces
is the normal behavior for example.  And you have an option by setting
environment variable to set the behavior the way you want it to be

I realize that you have found a difference in behavior of different
operating systems commands that exist between two different systems
and that it is causing you grief and annoyance.  You are upset about
that and frustrated that it is causing trouble for you.  I have run
into similar problems myself countless times.  I use many different
systems including many, many hpux machines and differences such as
these are always irritating.

But especially for the behavior cited neither behavior is particularly
right or particularly wrong.  Both behaviors just are.  Traditional
systems with heritage from different places behave differently.  If
you had been developing your programs on the other platform you would
not be complaining about this but rather complaining that HPUX did not
print spaces.  It is completely arbitrary.  The most productive use of
time would be to always endeaver to make scripts and programs as
portable as possible and as little sensitive to differences between
systems as possible.


reply via email to

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