`...` bug?

Hi

Can anyone tell me why I get AAA (without -e) and -e BBB ?

(using /bin/bash)

ruby

puts `echo -e AAA`, `echo -e BBB;`

=> AAA
-e BBB

Bash:

echo -e AAA; /bin/echo -e BBB; # -> both without -e

- So it must be in correlation with Ruby...

thanks Opti

Can't reproduce, they are both equal here:

% ruby -v -e 'puts `echo -e AAA`, `echo -e BBB;`'
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin20]
-e AAA
-e BBB

% ruby -v -e 'puts `echo -e AAA`, `echo -e BBB;`'
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
-e AAA
-e BBB

It seems to work if you remove the ";" from the second "echo"

Using ruby 2.6.6p146
irb(main):003:0> puts `echo -e AAA`, `echo -e BBB`
AAA
BBB

ruby -v -e 'puts `echo -e AAA`, `echo -e BBB`'
ruby 2.6.6p146 (2020-03-31 revision 67876) [aarch64-linux]
AAA
BBB

···

On Fri, Jul 30, 2021 at 10:22 AM Xavier Noria <fxn@hashref.com> wrote:

Can't reproduce, they are both equal here:

% ruby -v -e 'puts `echo -e AAA`, `echo -e BBB;`'
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin20]
-e AAA
-e BBB

% ruby -v -e 'puts `echo -e AAA`, `echo -e BBB;`'
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
-e AAA
-e BBB

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

Hi!
Anyone using Ruby 2.3.x ?

···

Am 30.07.21 um 11:21 schrieb Xavier Noria:

Can't reproduce, they are both equal here:

% ruby -v -e 'puts `echo -e AAA`, `echo -e BBB;`'
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin20]
-e AAA
-e BBB

% ruby -v -e 'puts `echo -e AAA`, `echo -e BBB;`'
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
-e AAA
-e BBB

Yes, but why does ';' make any difference --- in (pure) shell it doesn't...
So with Ruby 2.6.6 we still have this bug?

···

Am 30.07.21 um 13:11 schrieb Bruno Gerotto:

It seems to work if you remove the ";" from the second "echo"

Using ruby 2.6.6p146
irb(main):003:0> puts `echo -e AAA`, `echo -e BBB`
AAA
BBB

ruby -v -e 'puts `echo -e AAA`, `echo -e BBB`'
ruby 2.6.6p146 (2020-03-31 revision 67876) [aarch64-linux]
AAA
BBB

Good question.

There are some reasons.

* `cmd` (system(cmd)) uses /usr/bin/sh if cmd contains special characters like `;`, `&`, and so on.
* Ubuntu 20.4 uses dash for /usr/bin/sh

$ ls -la /usr/bin/sh
lrwxrwxrwx 1 root root 4 Apr 23  2020 /usr/bin/sh -> dash

* dash's echo doesn't recognize -e

$ dash -c 'echo -e foo'
-e foo

* /usr/bin/echo recognize `-e`

$ which echo
/usr/bin/echo

$ /usr/bin/echo -e foo
foo

Conclusion:

* `echo -e AAA` uses `/usr/bin/echo` and -e is recognized.
* `echo -e BBB;` uses `/usr/bin/sh -c 'echo -e BBB;'` (not exact same, it is for explanation) and it doesn't recognize -e.

···

On 2021/07/30 17:47, Die Optimisten wrote:

Hi

Can anyone tell me why I get AAA (without -e) and -e BBB ?

(using /bin/bash)

ruby

puts `echo -e AAA`, `echo -e BBB;`

=> AAA
-e BBB

Bash:

echo -e AAA; /bin/echo -e BBB; # -> both without -e

- So it must be in correlation with Ruby...

thanks Opti

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

mic drop.

The crowd goes wild. Well, at least I do.

···

On Jul 31, 2021, at 06:43, Koichi Sasada <ko1@atdot.net> wrote:

Good question.

There are some reasons.

* `cmd` (system(cmd)) uses /usr/bin/sh if cmd contains special characters like `;`, `&`, and so on.
* Ubuntu 20.4 uses dash for /usr/bin/sh

$ ls -la /usr/bin/sh
lrwxrwxrwx 1 root root 4 Apr 23  2020 /usr/bin/sh -> dash

* dash's echo doesn't recognize -e

$ dash -c 'echo -e foo'
-e foo

* /usr/bin/echo recognize `-e`

$ which echo
/usr/bin/echo

$ /usr/bin/echo -e foo
foo

Conclusion:

* `echo -e AAA` uses `/usr/bin/echo` and -e is recognized.
* `echo -e BBB;` uses `/usr/bin/sh -c 'echo -e BBB;'` (not exact same, it is for explanation) and it doesn't recognize -e.

On 2021/07/30 17:47, Die Optimisten wrote:
Hi
Can anyone tell me why I get AAA (without -e) and -e BBB ?
(using /bin/bash)
ruby
puts `echo -e AAA`, `echo -e BBB;`
=> AAA
  -e BBB
Bash:
echo -e AAA; /bin/echo -e BBB; # -> both without -e
- So it must be in correlation with Ruby...
thanks Opti
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

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...
PLEASE (everyone who did that): remove the code (or tell us, why it's
good to have it)!
Thats the way of "magic" which leads to unexpected results, leading to
better not using Ruby.
The ruby-user (programming person) can select to use system in 3 ways,
so when choosing one, there should not be other 'hidden' things!

(thats with many things in Ruby - exeptions everywhere!)

How is interested in creating a "small" Ruby-like language? --
where (too) complicated are not implemented, allowing only one
(generic/homomorph) way,
leaving all other things away?
Example; $VERBOSE $DEBUG ... # should be 0==nil/1/2....
There are MANY examples...

Opti

···

Am 31.07.21 um 14:43 schrieb Koichi Sasada:

Good question.

There are some reasons.

* `cmd` (system(cmd)) uses /usr/bin/sh if cmd contains special
characters like `;`, `&`, and so on.
* Ubuntu 20.4 uses dash for /usr/bin/sh

$ ls -la /usr/bin/sh
lrwxrwxrwx 1 root root 4 Apr 23  2020 /usr/bin/sh -> dash

* dash's echo doesn't recognize -e

$ dash -c 'echo -e foo'
-e foo

* /usr/bin/echo recognize `-e`

$ which echo
/usr/bin/echo

$ /usr/bin/echo -e foo
foo

Conclusion:

* `echo -e AAA` uses `/usr/bin/echo` and -e is recognized.
* `echo -e BBB;` uses `/usr/bin/sh -c 'echo -e BBB;'` (not exact same,
it is for explanation) and it doesn't recognize -e.

On 2021/07/30 17:47, Die Optimisten wrote:

Hi

Can anyone tell me why I get AAA (without -e) and -e BBB ?

(using /bin/bash)

ruby

puts `echo -e AAA`, `echo -e BBB;`

=> AAA
-e BBB

Bash:

echo -e AAA; /bin/echo -e BBB; # -> both without -e

- So it must be in correlation with Ruby...

thanks Opti

Unsubscribe:
<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

    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: