Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Oct 2020 15:23:38 +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:  <20201016152338.168831c5.freebsd@edvax.de>
In-Reply-To: <20201016113408.16d58d68@archlinux>
References:  <d50ba2c9-617f-6842-ef89-f5933be8f8b3@hotmail.com> <DB8PR06MB64427D88E17F02711EE657A3F6030@DB8PR06MB6442.eurprd06.prod.outlook.com> <20201016113408.16d58d68@archlinux>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
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@archlinux tmp]$ cat --help | head -1
> Usage: cat [OPTION]... [FILE]...
> [rocketmouse@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.





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



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20201016152338.168831c5.freebsd>