From owner-freebsd-questions@freebsd.org Sat Sep 9 15:28:01 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 2453BE1CA83 for ; Sat, 9 Sep 2017 15:28:01 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: from mail-io0-x22b.google.com (mail-io0-x22b.google.com [IPv6:2607:f8b0:4001:c06::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DD1526CDEB for ; Sat, 9 Sep 2017 15:28:00 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: by mail-io0-x22b.google.com with SMTP id n69so9589322ioi.5 for ; Sat, 09 Sep 2017 08:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-transfer-encoding; bh=9XvM+dc26M2el2/KK5l5SVZu6WFrjynoasikWzv8m+w=; b=WYV7TskUfe1VHjPdniasdoa4VZwooWcXcZBk9fIb4yWIL06zEHa9My3gCb1metnjMZ OkavjQVvjps+pu1z5H7mHsTGIdX/cb/WjZLg1Qw8l5ZNNDQWGJmqZ5QGjxHx++1O8gUD cai8yrp9zBf7KfnvXW8bB86StbefyqCqi3+rVQkgckzTM01di6ntzvfW0bFsyCBLLS9y /oG2yYIWthIv0IlUXWn8W1cqOOnk/X83SQZLyqjrmfDkQ92ATTTgGT2W5QpNP0NLyxyb Ko5j/yUdV/BWVxtbx4S/kxXH7ET7S0C3WB9EjNc3zJQPBg6voeQJsXF4BekHDdmoVEW9 IWPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-transfer-encoding; bh=9XvM+dc26M2el2/KK5l5SVZu6WFrjynoasikWzv8m+w=; b=N6UGeMV8qABMQDlYQ1n3WSIk/5y0gpiYDQ2Uu8lcriwNhNErF4cvhqhxRfnbYNw9xV bHkvLTYxeoi4cMZAmlKg7shkljM2m7gv3D3sZGhSNNOVYH6Obnu32MIJuB9Gm/M62Sli xMktDu1nq1nqn0zy1v8XfAVFBo+2chWUjiVfReB0gST58E1+TrmvjCihZJ38FmtK3BLG eHalpj/9xWHvsbB98eCjyNK2/UvxZ7WDla5LDU+HAhJNki3A1pRcJwnw4p1FS1Yv5PAc uJH759o9afr28uQbp7mKPZnRVN2Cpc7DTHb2U2BApXaIYe5OteZMHsb1FROWNnRD/lfj b/2A== X-Gm-Message-State: AHPjjUiUztuK6HcBnOjbhPwnxdR1gxtuUgTzWrAjJ7mW+FpN4D5ljc+/ sAiw7Nvb6GYGgA== X-Google-Smtp-Source: AOwi7QAagAyHj5h1B7z3jyV6bdkmHHAEBNp/xzWhPciLIHlH+jo4iduDKhtANrgsLL4jsBsekAemAA== X-Received: by 10.107.150.130 with SMTP id y124mr8185580iod.102.1504970880239; Sat, 09 Sep 2017 08:28:00 -0700 (PDT) Received: from [10.0.10.3] (cpe-74-141-88-147.neo.res.rr.com. [74.141.88.147]) by smtp.googlemail.com with ESMTPSA id h13sm2245181ith.36.2017.09.09.08.27.59 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 09 Sep 2017 08:27:59 -0700 (PDT) Message-ID: <59B4087B.2070005@gmail.com> Date: Sat, 09 Sep 2017 11:27:55 -0400 From: Ernie Luzar User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Yuri Pankov CC: Polytropon , "freebsd-questions@freebsd.org" Subject: Re: script code for end-line References: <59B332A3.1000205@gmail.com> <20170909030257.d2718c00.freebsd@edvax.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 15:28:01 -0000 Yuri Pankov wrote: > 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. > . > I read the man page on the test command and did not come away with the syntax to use in a script. An example showing usage inside of the "if" statement sure would be more helpful to understand how it works. Thanks