sh scripting question

Polytropon freebsd at
Fri Oct 16 13:23:45 UTC 2020

On Fri, 16 Oct 2020 11:34:08 +0200, Ralf Mardorf wrote:
> 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 at archlinux tmp]$ cat --help | head -1
> Usage: cat [OPTION]... [FILE]...
> [rocketmouse at archlinux tmp]$ cat ./--help | head -1
> test

For such files, using "--", the "stop processing command line
options" directive, is quite useful:

	# cat -- --help | head -l

This of course assumes that _after_ the offending filename,
no further command line arguments will be supplied.

> 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.

That's right, a "benevolent script" will eventually contain
many different kinds of defensive mechanisms, and will therefore
be much more complex (and surely prone to breaking, if not done
properly) than a script working on "normalized" filenames.

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list