From owner-freebsd-questions@freebsd.org Sat Sep 9 01:03:02 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 497EEE16536 for ; Sat, 9 Sep 2017 01:03:02 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailrelay10.qsc.de (mailrelay10.qsc.de [212.99.163.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.antispameurope.com", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B27BA722E1 for ; Sat, 9 Sep 2017 01:03:01 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay10.qsc.de; Sat, 09 Sep 2017 03:02:58 +0200 Received: from r56.edvax.de (port-92-195-85-107.dynamic.qsc.de [92.195.85.107]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 5281D3CBF9; Sat, 9 Sep 2017 03:02:58 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id v8912vLh002578; Sat, 9 Sep 2017 03:02:57 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sat, 9 Sep 2017 03:02:57 +0200 From: Polytropon To: Ernie Luzar Cc: "freebsd-questions@freebsd.org" Subject: Re: script code for end-line Message-Id: <20170909030257.d2718c00.freebsd@edvax.de> In-Reply-To: <59B332A3.1000205@gmail.com> References: <59B332A3.1000205@gmail.com> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-cloud-security-sender: freebsd@edvax.de X-cloud-security-recipient: freebsd-questions@freebsd.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mailrelay10.qsc.de with 8EE3568344F X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14 X-cloud-security: scantime:.1264 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Sep 2017 01:03:02 -0000 On Fri, 08 Sep 2017 20:15:31 -0400, Ernie Luzar wrote: > > I have a file that has blank lines with ^M in position one. > > I have this if [ "$end-line" = "^M"]; then > > > Is that the correct way to code that between the quotes? That will only match the literal string ^M (^ and M). String evaluation and comparison at this low level isn't a native skill of sh. There is a way of encoding characters as octal values, such as \015 for \r, which equals ^M and 0x0D, but /bin/test (which is [) can only compare strings. Here is a terrible workaround (not tested): if [ `echo ${end-line} | od -x | head -n 1 | awk '{ print $2 }'` = "000d" ]; then ... do something ... fi Check if there is already a tool for what you're trying to accomplish (e. g., tr, sed, recode, iconv). ;-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...