3 ms·
> No, let's just try it out (I've put both the Python and the plain sh -c invocations): > python2 -c 'import os; os.system("-x")' > sh -c -x sh: -c: opti
by zahlman 1y ago
> No, let's just try it out (I've put both the Python and the plain sh -c invocations):
> python2 -c 'import os; os.system("-x")'
> sh -c -x
sh: -c: option requires an argument
I can't reproduce this in Python (including my local 2.7 build), only using sh directly. Going through Python, `sh` correctly tells me that the `-x` command isn't found.
But now I'm wondering: how is one supposed to use `which` (or `type`, or `file`) for a program named `-x`, supposing one had it?
- o11c 1y agoUse: command -v -- -x The POSIX documentation for almost all commands (including `command`) says "The command utility shall conform to [...] Utility Syntax Guidelines" which specifies the behavior of `--`, even if it's not explicitly mentioned.
- akovaski 1y ago> I can't reproduce this in Python (including my local 2.7 build), only using sh directly. Same for me. It looks like the POSIX folks accepted the author's suggestion in 2022 and system() in glibc was updated in 2023. https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=sysdeps/posix/system.c;h=488b95163bb4d88bc1e2bac8b41e29fcf1530f96;hp=d77720a625e0d42a5cdca13961aae9db9c95ea78;hb=868506eb427c9dcc6d869cd4885679be04e1b7dd;hpb=31bfe3ef4ea898df606cb6cc59ac72de27002b01 https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=sysdeps... #include <stdlib.h> int main(void) { system("-x"); return 0; } ... > [pid 172293] execve("/bin/sh", ["sh", "-c", "--", "-x"], 0x7ffe221d2f58 /* 76 vars */) = 0