bin/101094: sh(1) can show wrong line numbers in its diagnostic messages

Yar Tikhiy yar at comp.chem.msu.su
Mon Jul 31 11:10:19 UTC 2006


>Number:         101094
>Category:       bin
>Synopsis:       sh(1) can show wrong line numbers in its diagnostic messages
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 31 11:10:09 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Yar Tikhiy
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
None
>Environment:
System: FreeBSD jujik.ramtel.ru 7.0-CURRENT FreeBSD 7.0-CURRENT #6: Tue Jun 27 14:45:05 MSD 2006 glebius at jujik.ramtel.ru:/usr/obj/usr/src/sys/JUJIK i386

>Description:
	sh(1) tries to keep track of the number of the current line
	in the current script file.  The main use of this is in
	diagnostic messages, such as "%s: %d: Syntax error ...",
	which come very helpful when debugging complex scripts.

	However, the line numbering is broken as soon as a line
	continuation is encountered.

>How-To-Repeat:
	Example 1:

%cat -b test.sh
     1  foo="\
     2  1\
     3  2\
     4  3\
     5  "
     6  esac
%sh -n test.sh
test.sh: 2: Syntax error: "esac" unexpected

	Example 2:

%cat -b test2.sh
     1  echo \
     2  1\
     3  2\
     4  3\
     5  4
     6  esac
%sh -n test2.sh
test2.sh: 3: Syntax error: "esac" unexpected

	In both cases, the error actually was in line 6.

	On the other hand:

%cat -b test3.sh
     1  echo \
     2  1 \
     3  2 \
     4  3 \
     5  4
     6  esac
%sh -n test3.sh
test3.sh: 6: Syntax error: "esac" unexpected

	In this case, the line number is correct.  Perhaps the problem
	appears when a single shell word is split across multiple lines.

>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list