bug-bash
[Top][All Lists]
Advanced

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

Re: bizarre trap behavior while reading a file


From: Greg Wooledge
Subject: Re: bizarre trap behavior while reading a file
Date: Mon, 28 Mar 2011 08:11:02 -0400
User-agent: Mutt/1.4.2.3i

On Fri, Mar 25, 2011 at 02:25:35PM -0700, tytus64 wrote:
> while read line
> do
>     line_num=`expr $line_num + 1`
>     echo $line_num: $line >> ./out.log
> done < $log_file

Although it's not directly related to your question, I feel obliged
to point out that you can increment a variable without forking an
external expr command:

line_num=$((line_num+1))    # POSIX sh compatible

or

((line_num++))              # Bash only

You only need expr when writing for the Bourne shell.



reply via email to

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