From owner-freebsd-questions Sun Mar 31 14:30: 8 2002 Delivered-To: freebsd-questions@freebsd.org Received: from wonkity.com (wonkity.com [63.93.4.4]) by hub.freebsd.org (Postfix) with ESMTP id E9D7837B41C for ; Sun, 31 Mar 2002 14:30:04 -0800 (PST) Received: from wonkity.com (localhost.wonkity.com [127.0.0.1]) by wonkity.com (8.12.1/8.11.6) with ESMTP id g2VMU4uF067565 for ; Sun, 31 Mar 2002 15:30:04 -0700 (MST) (envelope-from wblock@wonkity.com) Received: from localhost (wblock@localhost) by wonkity.com (8.12.1/8.12.1/Submit) with ESMTP id g2VMU3t6067562; Sun, 31 Mar 2002 15:30:03 -0700 (MST)?g (envelope-from wblock@wonkity.com) Date: Sun, 31 Mar 2002 15:30:03 -0700 (MST) From: Warren Block To: Eric Boucher Cc: FreeBSD Subject: Re: exact length of a line in a file with the read command In-Reply-To: <20020331202713.66909.qmail@web9401.mail.yahoo.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sun, 31 Mar 2002, Eric Boucher wrote: > I want to know the exact length of each line in a > file. But it seems that when the file begin or end > with a space caracter of a tab caracter, the "read" > command in bourne shell delete them and return me only > what begin with a letter and end with a letter. So > when I try to know the exact length of a file (I tried > with both lenght command from "expr" and "nawk"). So > if for example, a line is like this (note: > mean the real space caracter and the tab > caracter) > toto > the read return me only: > toto > which is of length = 4 > but it is suppose to be of length = 6 This just worked for me: #!/bin/sh IFS="" echo "Enter a string" read tester echo $tester echo ${#tester} If a shell script is going to be non-trivial, I just use Perl. -Warren Block * Rapid City, South Dakota USA To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message