From owner-freebsd-questions@freebsd.org Mon Oct 19 05:23:09 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 00CB7445111 for ; Mon, 19 Oct 2020 05:23:09 +0000 (UTC) (envelope-from ralf-mardorf@riseup.net) Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CF4sR6HkSz466y for ; Mon, 19 Oct 2020 05:23:07 +0000 (UTC) (envelope-from ralf-mardorf@riseup.net) Received: from capuchin.riseup.net (capuchin-pn.riseup.net [10.0.1.176]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4CF4sF3ySvzFf8w for ; Sun, 18 Oct 2020 22:22:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1603084977; bh=IKbrL56SrlY4BMl3wDj9gx2pE5Z0oKXaRKAaooTFbfM=; h=Date:From:To:Subject:In-Reply-To:References:From; b=ShYa/suGjk+aoW9qKXYatzafZMmpHbH5xYADyeMnFFYTAckjXydKtnkIm++wSrUrv 8TkkHn/V9DlUBKOs8AJ1o/RKpA6dkvH0AIqYifTQTe6NzGtX3CyAwkgpdY3Qz+bQQN jiWGR1PV/RhlDoEFzDtwdWFiLCeuwMU+ZMgOyL50= X-Riseup-User-ID: 329D4C3F918F05FB6D0AE3BADC94CF327FD2CCE394F647268D9F470A2212012A Received: from [127.0.0.1] (localhost [127.0.0.1]) by capuchin.riseup.net (Postfix) with ESMTPSA id 4CF4sF0Qrrz8wqX for ; Sun, 18 Oct 2020 22:22:56 -0700 (PDT) Date: Mon, 19 Oct 2020 07:22:43 +0200 From: Ralf Mardorf To: freebsd-questions@freebsd.org Subject: Re: sh scripting question Message-ID: <20201019072243.483c689e@archlinux> In-Reply-To: <20201018144327254822114@bob.proulx.com> References: <20201016113408.16d58d68@archlinux> <24457.35680.223661.203846@jerusalem.litteratus.org> <444kmtudmy.fsf@be-well.ilk.org> <20201018144327254822114@bob.proulx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4CF4sR6HkSz466y X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=riseup.net header.s=squak header.b=ShYa/suG; dmarc=pass (policy=none) header.from=riseup.net; spf=pass (mx1.freebsd.org: domain of ralf-mardorf@riseup.net designates 198.252.153.129 as permitted sender) smtp.mailfrom=ralf-mardorf@riseup.net X-Spamd-Result: default: False [-4.64 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[riseup.net:s=squak]; NEURAL_HAM_MEDIUM(-1.08)[-1.077]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[198.252.153.129:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; DWL_DNSWL_LOW(-1.00)[riseup.net:dkim]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[riseup.net:+]; DMARC_POLICY_ALLOW(-0.50)[riseup.net,none]; NEURAL_HAM_SHORT(-0.95)[-0.954]; NEURAL_HAM_LONG(-1.01)[-1.006]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; ASN(0.00)[asn:16652, ipnet:198.252.153.0/24, country:US]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-questions]; RCVD_IN_DNSWL_LOW(-0.10)[198.252.153.129:from] 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: Mon, 19 Oct 2020 05:23:09 -0000 On Sun, 18 Oct 2020 14:37:55 -0600, Bob Proulx wrote: >And yet just the same the shell does handle whitespace and arbitrary >characters in file names easily. > > while IFS= read -r line; do > printf "|%s|\n" "$line" > done < file1 This just reads the file names from a file with a list of file names, now it depends what a user wants to do with those file names. Assuming it is intended to edit those file names depending on filter rules, the script could become very clumsy. The input file names might be "my_fine_stereo_song_named_my_cat_your_dog.wav" "fine_stereo_song_from_your_aunt_called_my_bird_your_bee.wav" and similar. The script should depending on filter rules, process those files and generate new files names "my_odd_stereo_song_left_channel_named_my_cat_your_dog.wav" "my_odd_stereo_song_right_channel_named_my_cat_your_dog.wav" "your_aunts_wonderful_stereo_song_remixed_to_mono_named_my_bird_your_bee.wav" and similar. It's easier to care for a single word separator "_", then to care for arbitrary word separators " ", " *** ", ";", " ", " : " and alternatively CamelCase, too, each on arbitrary positions. Keep in mind, the script already needs to detect the composer mentioned somewhere in the file name etc.. If I would add arbitrary word separators to my already broken English, it would make my sentences much harder to understand. IfIWould ; add.arbitrary <> word seperators. ToMy.already : broken -English,it,would MakeMy. sentences much-HarderTo understand. >And I think everyone is in agreement that the filenames that were >chosen were not the file names that any Unix person would choose to >name their files. No disagreement there. The reason that we are in agreement is, that it is difficult to handle freakish file names. Often enough we note, that our first idea how to name paths and/or directories wasn't optimal, already without using freakish word separators or other odd ideas. On Sun, 18 Oct 2020 15:44:20 -0600, Bob Proulx wrote: >$ find . -type f -exec sh -c 'ls -ld "$@"' sh {} + When writing a script as a file, we do want to write the scripts readable. A script becomes unreadable, if it becomes one long line. Command line is another story.