Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Oct 2020 15:19:42 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Ralf Mardorf <ralf-mardorf@riseup.net>
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> <c6096f5d-84f5-af81-7407-9bda06c7b240@panix.com> <20201016063211.2f8b3a74@archlinux>

next in thread | previous in thread | raw e-mail | index | archive | help
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, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20201016151942.e01600b6.freebsd>