From owner-freebsd-questions@freebsd.org Sat Sep 9 01:23:42 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 DA0B6E17946 for ; Sat, 9 Sep 2017 01:23:42 +0000 (UTC) (envelope-from yuripv@gmx.com) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "mout.gmx.net", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3FB9172D55 for ; Sat, 9 Sep 2017 01:23:42 +0000 (UTC) (envelope-from yuripv@gmx.com) Received: from [192.168.1.2] ([62.183.127.59]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0LxgHz-1dNCAx32Kp-017CXj; Sat, 09 Sep 2017 03:23:33 +0200 Subject: Re: script code for end-line To: Polytropon , Ernie Luzar Cc: "freebsd-questions@freebsd.org" References: <59B332A3.1000205@gmail.com> <20170909030257.d2718c00.freebsd@edvax.de> From: Yuri Pankov Message-ID: Date: Sat, 9 Sep 2017 04:23:32 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170909030257.d2718c00.freebsd@edvax.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:+38mDh2xhIfkE/WJoHDi3cfriv0QPrlXaZNBRddb9bl/mBNfZ74 n431KO6NzJjgXinPCFx0WTHTIn5BypyV/oVKG+tOnka8MjinZA3A13rXioidN2LFqUMSwyG lxQmf8WzKDqw3H904buHvZ32NlmOUdINfz3KBYXdNCAkKstFzX5IlCFsGFa34RPlVDLC298 fXtncmGb8zf0UqlmWIhSQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:1J0DReuHh6s=:qH0gfpoAoikzNhEWdfAtQi GCtRfG2i0EYLDSns4TTuOMacPbzcyyFqilnZ3DPkr+moQVhnKRCmYL9FELH15GPMnH1/tvR3M P1v9kp+/lsQlSrgTzaDKv7UbQTjP6DDxRSffPRIzA5Tyk+/7Z86jQCQjz32b6X8W7PTuQxuMl tYkFBecoLsms1Vl7pkFEltI8Kq2N/iTQEwYvLbJ9C+bAxmu2ui9GTdUlWamGANRGgzzYlIJcs h1anx355WacF3bSWuRPFHYwkwLKjpoppyygAL/A/Yj+mdH6b8HwYgSnIkVRL9JkJDmPmqVjyX F5dYUTI18E0pcgvm3TPC9LynbWmmljkV/Q86j5VkU/fCmLP67/tE505fVFShkIodGgiAj5ZPT xj+OkzpUHFB0mgPyV8z0+ofQviPPIrcTSU3Zr50H9OrWgRywz27LxlSWxFMyUdRryOJi1bn2l 9xVndt+KEcFZOihlsB/sxKRdpFTpZpJ/ICH22jiV4NduHiOSQL9muukguK+pfGyYZznSBKhMk kMeScK+4oLVxGX9Qw+u0fVN7dndV/DooxLnHUmlFX2MtjuWnriBihIOGwjmOKHTPt78JcnEFe oOlSoBk3+fMQcJ51QXUmvmxJhlN0RSDy6pRPXCxxSvgnFpX4qaV/r7DwTbj48HjrV7HDx5r4i 7e0GYj4qieJsrAiOuGcJp+EqQag12uqaTnnVhSnW6yS9a+Ts3TJKI7vuYfqX4Cxcy1GncmbkZ 2h/LnBY9UY0UNWSbIl7V+jZMzpxiXQ+vuTBeezQwrTlJzmZYZ8fVmilnDuRdl2rUoN/EbK+pJ 4Mp06hkg2EsNbrxNGDdTqkCh6Q6n7BFCcMDM6gNWrmlOHZ9PfM= 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:23:43 -0000 On Sat, 9 Sep 2017 03:02:57 +0200, Polytropon wrote: > 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). ;-) Actually, you can insert real ^M characters and /bin/test should be able to handle them - press ctrl+V ctrl+M.