ok - Thank you!
Is there any documentation about that??
WHY does Ruby look into the string?!?
Problem:
`echo $SHELL` # -> /bin/bash
`echo $SHELL; ` # -> /bin/bash
Maybe $ is such a special character, too.
-> Who the hell programmed that?? That can't be expected...
You're being rude. Yes, that can be expected, because this is well documented.
PLEASE (everyone who did that): remove the code (or tell us, why it's
good to have it)!
Why WOULDN'T it look at the string? Is your command named "echo $SHELL"? or is it named "echo" and has an argument of "$SHELL"? Who's supposed to decide that? It's a complicated combination of ruby and your OS/libc and your shell (if it is involved).
9978 % ruby -e 'system "echo", "$SHELL"'
$SHELL
9979 % ruby -e 'system "echo $SHELL"'
/bin/bash
Thats the way of "magic" which leads to unexpected results, leading to
better not using Ruby.
Not reading the documentation leads to unexpected results.
See "ri Kernel#spawn" as well as exec, system, and spawn (which has almost all the doco)). There's a lot of complex ways to do this because, unfortunately, there's just way too many ways people want to do this. The full complexity of `spawn` is huge... but so is the output from `man bash`... it's almost 5k lines long on my system and a LOT of it centers around expansion and execution.
Here's the relevant doco you want to refer to:
If the string from the first form (exec("command")) follows these simple
rules:
* no meta characters
* no shell reserved word and no special built-in
* Ruby invokes the command directly without shell
You can force shell invocation by adding ";" to the string (because ";" is a
meta character).
Note that this behavior is observable by pid obtained (return value of spawn()
and IO#pid for IO.popen) is the pid of the invoked command, not shell.
What isn't well documented is the meta-chars... I had to look that up in the C code:
/*
* meta characters:
*
* * Pathname Expansion
* ? Pathname Expansion
* {} Grouping Commands
* Pathname Expansion
* <> Redirection
* () Grouping Commands
* ~ Tilde Expansion
* & AND Lists, Asynchronous Lists
* | OR Lists, Pipelines
* \ Escape Character
* $ Parameter Expansion
* ; Sequential Lists
* ' Single-Quotes
* ` Command Substitution
* " Double-Quotes
* \n Lists
*
* # Comment
* = Assignment preceding command name
* % (used in Parameter Expansion)
*/
But I didn't find this to be too surprising... Basically, anything that COULD be a wierd character in bash is probably assumed to be a meta character by ruby.
···
On Aug 2, 2021, at 09:52, Die Optimisten <inform@die-optimisten.net> wrote: