53 lines
1.7 KiB
Plaintext
53 lines
1.7 KiB
Plaintext
Filename and pathname should be prefixed to avoid missing filenames starting with a dash when globbing files as program option.
|
|
|
|
== Why is this an issue?
|
|
|
|
Within the command, arguments and filenames as options are passed as strings.
|
|
Programs may misinterpret files as arguments if the file name starts with a single or double dash.
|
|
When filenames are specified using glob, files whose names begin with a dash are not included in the scope.
|
|
For example, if a file is named "-f" and passed as an argument to a command such as "rm", it may be interpreted as a command line option instead of a file, causing unexpected behaviour.
|
|
This issue affects all instructions processing shell commands.
|
|
|
|
== How to fix it
|
|
|
|
To avoid this issue, using "./" before the file name will cause it to be interpreted as a file and not an option.
|
|
Additionally, adding "--" at the end of command line arguments indicates the end of options and any subsequent arguments will be treated as file names.
|
|
However, this fix should only be used if the command supports it as expected.
|
|
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,docker,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
RUN rm *
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,docker,diff-id=1,diff-type=compliant]
|
|
----
|
|
RUN rm ./*
|
|
RUN rm -- *
|
|
----
|
|
|
|
== Resources
|
|
* https://dwheeler.com/essays/filenames-in-shell.html[Filenames and Pathnames in Shell: How to do it Correctly]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Prefix files and paths with `./` or `--` when using glob.
|
|
|
|
=== Highlighting
|
|
|
|
Highlight the entire command which is using glob for file or path option.
|
|
|
|
'''
|
|
endif::env-github,rspecator-view[]
|