From owner-freebsd-questions@freebsd.org Fri Oct 16 10:26:13 2020 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BD2B042FBCE for ; Fri, 16 Oct 2020 10:26:13 +0000 (UTC) (envelope-from bourne.identity@hotmail.com) Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-oln040092070024.outbound.protection.outlook.com [40.92.70.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail.protection.outlook.com", Issuer "GlobalSign Organization Validation CA - SHA256 - G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CCMkX43Pvz4kBG for ; Fri, 16 Oct 2020 10:26:12 +0000 (UTC) (envelope-from bourne.identity@hotmail.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HqLKypBoea8ckA5DD6jVvxxcrb4jWpf1hCeQileVRKPjf6339bC5SAywEGJBO1cORhkGVcqiGcBb+E47CuvmbkeneZnKVjV5zVLpGCnlQLvRjItAIsvXwP59tDndXcQdlBzUVouGTH16MeW9aKIti9QDxup8TTpMgcq2DXTP+DVX9hVHDXJjzn8WgkOXYMwBadxoD0JFCTYWAK1YoKsIBe6iEAd7eXIaZjo7cIdmbWawjTI+/f7QpOYR3XPbXMAuaQvqpq3IKs0rAi9JZ7IbpzmbfroLKc8oOC0IYNV++ZHT/KTP7H7OtUG/Z/nsvkcbcttzdzD+rnoKLUb+vzF2Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C0ZsKaM/Tfjr1uiMkD/OqF4OW4dSCOrsZN2EnAwtFQY=; b=m1GLk+8XcUijCBGkZEuDXY/E+5TaAiihRPezeJlDvNbrDTtKhFKhiz67PGwg3+Pc9A+yDzv1TiNQ+BhPk3uvQg6KrMDIapTPB3nr9ppzN0e+vlEfOvht1Za9/rWmBNU1jiibnT5gcHGXQBgKHH10MgY5fxKRhst0nxaOPDcCUhuBa9loEImHCjDWA46gAU0c0VANL8EwzlywKo2xjBRkoLV0pnyrEFSdpwPTAMJ3kmEnwawtait6v8jQbsY9SusaXET7ZOupX8mv7GL7HLS98Y/+wRS6JZEmuMVqgMfX319nWS072psNXeXDUdZuM6fxWJFkBbx2dxMLDA5Ud5qAnQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C0ZsKaM/Tfjr1uiMkD/OqF4OW4dSCOrsZN2EnAwtFQY=; b=HfHB7dbOpwxRtFYXy42l9XHe7EJBQhNdeMhXUUyw3dB/C26pQWjZ3bwx7X4UeVPfxyYm//2zCe+Xf709wYjFgJWB4piJDany6CkQnGF0SunPxtaii4fhVfuo06AqB5hoJUIC5MRI9D3EL7gEx60bhKnv99XH8vJC0gSJb7IYYu3xBlbsVh+O8wGJeCrrsVE5ex7bI/jGNofgWrN/W0umzQEHjHFEt2EZkvpbiIHkWjoyWoWDQbCyQb/RhhyAWLCExJjqygx1r6mjbKCbpB5b02uF61rnvkNFGHIVeabcXvG321He+S4ss6knkAjWWp2EE639DdCGcaQH86VUPl24MA== Received: from VE1EUR03FT050.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::43) by VE1EUR03HT230.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.23; Fri, 16 Oct 2020 10:26:08 +0000 Received: from DB8PR06MB6442.eurprd06.prod.outlook.com (2a01:111:e400:7e09::4a) by VE1EUR03FT050.mail.protection.outlook.com (2a01:111:e400:7e09::465) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Fri, 16 Oct 2020 10:26:08 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:6400E228B156600F70AFF969844B3B798CE84AABF3F6C068AAEB984A8F56B95F; UpperCasedChecksum:BC058B2AAA6A65622762F5F008F0903D1A7AC41BCD8E8E467359317BCA3F137F; SizeAsReceived:8760; Count:47 Received: from DB8PR06MB6442.eurprd06.prod.outlook.com ([fe80::5822:2d5d:a176:574f]) by DB8PR06MB6442.eurprd06.prod.outlook.com ([fe80::5822:2d5d:a176:574f%9]) with mapi id 15.20.3477.023; Fri, 16 Oct 2020 10:26:07 +0000 Subject: Re: sh scripting question To: Ralf Mardorf , freebsd-questions@freebsd.org References: <20201016113408.16d58d68@archlinux> From: Manish Jain Message-ID: Date: Fri, 16 Oct 2020 15:55:59 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 In-Reply-To: <20201016113408.16d58d68@archlinux> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-TMN: [vJNHefwZ52/QSAo9he8QHqb+JRKLFDLHcEwzuQl/+O8=] X-ClientProxiedBy: BMXPR01CA0043.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:c::29) To DB8PR06MB6442.eurprd06.prod.outlook.com (2603:10a6:10:126::7) X-Microsoft-Original-Message-ID: <7517304b-b418-4cef-0b4f-ba0c80a854f8@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.2] (103.195.202.206) by BMXPR01CA0043.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:c::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Fri, 16 Oct 2020 10:26:06 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: dac8d98c-7a97-4c2c-0733-08d871bde472 X-MS-TrafficTypeDiagnostic: VE1EUR03HT230: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fo+zAR8rCP7YSuxHFj1DGA/vUoVo7kRS+SPWgyaLbemZ0SmG/yqqXaT5S/UZGSeCdnsAgyRusPeAaPBOGkeuRYggHUng56iPXq3Ib5AHMfwmNqLRsbslwcokEp93g35OyfnCJG2W02lzODtiYHNpCrWmgJq7Uh5YtmDp+YST5ptN6IZGsxaV3o7drNITIxmYoGJE77IAeLd3Q+z4B5iknA== X-MS-Exchange-AntiSpam-MessageData: OGfP9IBsLr0Q67atWAcZ0+x7Gu9RHRaOtGa0aJIukWjUcfV58AXXzAqAxtVMkfsyE3rKEDcuAUgx4wnixmOQAu+Fzh944XIlTFhQn/hK3p8ep6A4sDSgZNFTwF0YQdTOCXl/YctKPSWXs6hiuaOIkA== X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: dac8d98c-7a97-4c2c-0733-08d871bde472 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2020 10:26:07.0730 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT050.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT230 X-Rspamd-Queue-Id: 4CCMkX43Pvz4kBG X-Spamd-Bar: +++++++ Authentication-Results: mx1.freebsd.org; dkim=pass header.d=hotmail.com header.s=selector1 header.b=HfHB7dbO; dmarc=pass (policy=none) header.from=hotmail.com; spf=pass (mx1.freebsd.org: domain of bourne.identity@hotmail.com designates 40.92.70.24 as permitted sender) smtp.mailfrom=bourne.identity@hotmail.com X-Spamd-Result: default: False [7.51 / 15.00]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:40.92.0.0/15:c]; FREEMAIL_FROM(0.00)[hotmail.com]; DKIM_TRACE(0.00)[hotmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(0.00)[hotmail.com,none]; NEURAL_HAM_SHORT(-0.00)[-0.003]; RECEIVED_SPAMHAUS_PBL(0.00)[103.195.202.206:received]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_ALLOW(0.00)[microsoft.com:s=arcselector9901:i=1]; FORGED_MUA_THUNDERBIRD_MSGID_UNKNOWN(2.50)[]; FREEMAIL_ENVFROM(0.00)[hotmail.com]; ASN(0.00)[asn:8075, ipnet:40.80.0.0/12, country:US]; DWL_DNSWL_NONE(0.00)[hotmail.com:dkim]; RECEIVED_SPAMHAUS_XBL(5.00)[103.195.202.206:received]; R_DKIM_ALLOW(0.00)[hotmail.com:s=selector1]; RCVD_COUNT_FIVE(0.00)[5]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_MEDIUM(-0.34)[-0.335]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_SPAM_LONG(0.35)[0.351]; RCVD_IN_DNSWL_NONE(0.00)[40.92.70.24:from]; RWL_MAILSPIKE_POSSIBLE(0.00)[40.92.70.24:from]; GREYLIST(0.00)[pass,meta]; MAILMAN_DEST(0.00)[freebsd-questions] X-Spam: Yes X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Oct 2020 10:26:13 -0000 On 2020-10-16 15:04, Ralf Mardorf wrote: > On Fri, 16 Oct 2020 13:42:17 +0530, Manish Jain wrote: >> -------- Forwarded Message -------- >> Subject: Re: sh scripting question >> Date: Fri, 16 Oct 2020 13:39:06 +0530 >> From: Manish Jain >> To: Ralf Mardorf >> >> On 2020-10-16 10:02, Ralf Mardorf wrote: >>> On Thu, 15 Oct 2020 23:14:13 -0400, Kurt Hackenberg wrote: >>>> On 2020-10-15 23:05, Bob Proulx wrote: >>>> >>>>> Oh you are tormenting us now. :-) There are some subtle issues >>>>> here. >>>> >>>> >>>> Maybe a shell is the wrong tool. >>> >>> Exactly! Scripts are useful to handle tasks, such as dealing with >>> reasonable file names. A script should work around reasonable tricky >>> file names, but at some point bothering with really freakish file >>> names isn't worth the effort. Actually file names should be >>> compatible with shell, if they are intended to be used with shell >>> scripts. To some extent we could use shell scripts, to write little >>> programs, that probably better should be written in a programming >>> language. At some extent a programming language is required, a shell >>> script can't do the job at all or at best it could do the job, but >>> not with reasonable effort. >> >> >> I would strongly disagree with that. If a problem can be solved with a >> shell script - and Robert Huff's problem is easily solvable with a >> simple Bourne shell script, then a shell script must be what is used >> to solve the problem. > > We do not disagree here. The OP's "problem" isn't a big problem for a > shell script, assuming we are talking about file names such as > > foo bar 10-inch.txt > > and not > > foo "bar" \ 10".txt > > Names read from a file containing a list of file names is one thing. The > next step is how the script should proceed using the file names. > Handling even the most freakish string is doable, but depending on > what should be done next with this string, it's not necessarily > pleasant, especially not when the content of the string conflicts with > shell conventions. > > Imagine a file named > > - > > or > > -h > > or > > --help > > etc., then add the file name behind a command. > > Yes, you could use a workaround, such as adding a path. > > [rocketmouse@archlinux tmp]$ cat --help | head -1 > Usage: cat [OPTION]... [FILE]... > [rocketmouse@archlinux tmp]$ cat ./--help | head -1 > test > > However, you easily could end up with a script containing more lines > that workaround offended conventions, than containing lines for what > actually should be done. Hi Ralf, This is where I actually have an entirely different philosophy. When you create a file with a leading - (or for that matter, weird characters such as * anywhere in the filename), I think the filesystem driver (i.e. the kernel) should throw a warning: "Do you really want a filename like that ?" Actually, I would go one step ahead and have kernel drivers and users agree on a Unix Portable File Naming Convention, which should debar rotten file names in the first place to everyone except the root user (and even he should get a warning on violations). A few examples of what the Convention should debar: - in the leading position . in the trailing position * anywhere in the filename | anywhere in the filename I could think of a few more, but I think you get the idea. Anyway, Robert's problem I do not think relates to weird filenames as far as I can see. Regards, Manish Jain