Bug 211029

Summary: Add warning about calling `system("-some-tool")` that fails (although it is a valid `sh` command)
Product: Documentation Reporter: Ciprian Dorin Craciun (ciprian.craciun)
Component: man-pagesAssignee: documentation_man-pages (documentation_man-pages)
Status: NEW ---    
Severity: normal    
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: Subsystem:
Regression: No Bisected commit-id:

Description Ciprian Dorin Craciun 2021-01-04 13:08:28 UTC
First of all please note I've already reported this bug to the `glibc` maintainers:

  https://sourceware.org/bugzilla/show_bug.cgi?id=27143

Their response was (I'm pasting together multiple replies):

~~~~
Unfortunately, this bug is required by POSIX, which requires passing the string as an argument to the -c option of the shell.

[...]

POSIX specifies the exact value of the -c argument.

The manual pages are maintained as a separate project: https://www.kernel.org/doc/man-pages/
~~~~

Therefore I'm opening a feature request here for the `system(3)` man page.



As such may I suggest adding a note in the `bugs` section of the man page that states something on the lines:
~~~~
If the command starts with a hyphen (as in `-some-tool`), due to the way `system(3)` is implemented in `glibc` and the way `sh(1p)` interprets when invoked as `sh -c -some-tool`, such a command will fail with an undefined behaviour.

A simple workaround for such a situation is to always prefix your commands with a space when such a command would start with a hyphen.
~~~~
Comment 1 Ciprian Dorin Craciun 2021-01-04 15:51:36 UTC
OK, I've opened an issue on the POSIX bug tracker:

  https://www.austingroupbugs.net/view.php?id=1440