From owner-freebsd-questions@freebsd.org Fri Oct 16 13:19:56 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 333BE4356E4 for ; Fri, 16 Oct 2020 13:19:56 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mout.kundenserver.de", Issuer "TeleSec ServerPass Class 2 CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CCRZx6JYSz3SQN for ; Fri, 16 Oct 2020 13:19:53 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de ([94.222.3.6]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPA (Nemesis) id 1MNtny-1knFoc4BgW-00OEzG; Fri, 16 Oct 2020 15:19:43 +0200 Date: Fri, 16 Oct 2020 15:19:42 +0200 From: Polytropon To: Ralf Mardorf Cc: freebsd-questions@freebsd.org Subject: Re: sh scripting question Message-Id: <20201016151942.e01600b6.freebsd@edvax.de> In-Reply-To: <20201016063211.2f8b3a74@archlinux> References: <24456.60388.135834.43951@jerusalem.litteratus.org> <20201015204226099763897@bob.proulx.com> <20201016063211.2f8b3a74@archlinux> 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-Provags-ID: V03:K1:TPJTvPJuWYFI711kuc44MXCS+sMV/12itL+vidA/AEHx5T647/+ Ga/jRZpeegBPNQ2njO/zVe8HfhV33hfrrOPYVvferLOLHSgTUHeK4gsfBAepJP8G/4F9+H0 fXgyKbLj1+g30AjEwRZHROQOzIJ+j9H+dSPRRDdHaxXFDMfb/vDQEvCvNp0K9oGNqLZUzNJ +9aq4hI1ELnO9RTCZ/vYg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:QYzuMiaALAA=:eSR/YHazJN3RzlOYeonjQb UNfnYZJrQTk8pPqDXH7B2eR6yjM39p3gKV961gVzqKIqMsBjjm506+gSWymXa7oXaGC6iPQ0R z5+YQI2mxm186O371cGJgTxnowtiwY4c0idq6+jW6YJaYkHP7CQEBzDz/4+d5i9bzuvixXnFs stVezGm7POfLxpjv026B9/ASVlUKExI2p07LAooI2eSUTWyAKjp8WMAqnY060iuyi+2jjsPKM yNs9X0oPmh8bQrPOMS/Qw5KlQW1WwhbdbC8Jep3C/HpJ6hPy5PtIYJK1RPwFj1GyMMl7zskKG g2WleDtVvrBPE2Pj+cmgTct7cKwfdjdJvV8kiR9gCl7/a778xzlNoLWb6kyTlLdLxd40F1FU/ MuQk+ycnHHaRwTza80m3dTvcP3V6zPCo635SA97ge6zZZ3dvE7Db2rvAipaJ4 X-Rspamd-Queue-Id: 4CCRZx6JYSz3SQN X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of freebsd@edvax.de has no SPF policy when checking 212.227.17.24) smtp.mailfrom=freebsd@edvax.de X-Spamd-Result: default: False [-0.02 / 15.00]; HAS_REPLYTO(0.00)[freebsd@edvax.de]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; HAS_ORG_HEADER(0.00)[]; NEURAL_HAM_SHORT(-1.05)[-1.046]; RCPT_COUNT_TWO(0.00)[2]; RECEIVED_SPAMHAUS_PBL(0.00)[94.222.3.6:received]; RCVD_TLS_LAST(0.00)[]; R_DKIM_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:8560, ipnet:212.227.0.0/16, country:DE]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.63)[-0.631]; REPLYTO_EQ_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-0.75)[-0.747]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[edvax.de]; AUTH_NA(1.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MID_CONTAINS_FROM(1.00)[]; RCVD_IN_DNSWL_NONE(0.00)[212.227.17.24:from]; R_SPF_NA(0.00)[no SPF record]; RWL_MAILSPIKE_POSSIBLE(0.00)[212.227.17.24:from]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-questions] 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 13:19:56 -0000 On Fri, 16 Oct 2020 06:32:11 +0200, 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. There is a significant problem with this statement (even though I can understand its intention): At what point does a filename become "not reasonable"? Stupid people do stupid things. Stupidly programmed programs do stupid things to filenames, too. Scripts usually do not care. They typically (!) are not limited to a subset of valid filenames, they work on _all_ filenames. Just imagine you want to copy or delete a file, but the program in question complains that you cannot do it with _this_ file because its name is not reasonable... that would be a really strange situation... > A script should work around reasonable tricky > file names, but at some point bothering with really freakish file names > isn't worth the effort. Depends. If your scope involves processing 1000+ files delivered by your stupid coworkers, you will surely develop a script that fights all the freakish things you will encounter by iterating over those filenames. As I mentioned in my first reply, this is absolutely possible, but not _trivial_ anymore. In my opinion, the goal defines the amount of work you will put into it. > Actually file names should be compatible with > shell, if they are intended to be used with shell scripts. There is a problem. Filenames are subject to restrictions. The first level of restrictions is imposed by the filesystem. It defines a maximum length as well as reserved characters, such as "/" for the directory separator, and "." and ".." which are handled in a specific way. The second level of restrictions comes from the shell. It includes, but is not limited to, using " " (space) as the command and options separator, "-" as the options prefix, and may contain many more, such as "*" or "?". While all of them are valid within a filename, they probably _should_ not be in a filename. If a file should have a name valid on other filesystems which are not as generous as UFS, a third level of restrictions will apply, originating from the limitations of the foreign filesystem, and can even include "forbidden filenames" such as "COM1:". :-) > 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. Fully correct, but also suffers from the lack of a definition of "reasonable" that works everywhere every time. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...