dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* possible wrong behaviour when -s and -c are both used
@ 2022-03-11  4:25 Christoph Anton Mitterer
  2022-03-11 10:12 ` Harald van Dijk
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Anton Mitterer @ 2022-03-11  4:25 UTC (permalink / raw)
  To: dash

Hey.

I've noted that dash gives different behaviour when both -s and -c are
used, depending on their order:

calestyo@heisenberg:~$ cat script
date
calestyo@heisenberg:~$

calestyo@heisenberg:~$ dash -s -c 'echo foo' script
foo
$     <--- this is dash's prompt, and it reads input from stdin
calestyo@heisenberg:~$ dash -c 'echo foo' -s script
foo
calestyo@heisenberg:~$ 


POSIX specifies[0]:
> -c
>    Read commands from the command_string operand.
>    ...
>    No commands shall be read from the standard input.


So I'd say -c is ought to override -s ... but in any case I'd guess
it's unintended that the order of the two changes the behaviour?!


Thanks,
Chris.


[0] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: possible wrong behaviour when -s and -c are both used
  2022-03-11  4:25 possible wrong behaviour when -s and -c are both used Christoph Anton Mitterer
@ 2022-03-11 10:12 ` Harald van Dijk
  2022-03-11 17:15   ` Christoph Anton Mitterer
  0 siblings, 1 reply; 3+ messages in thread
From: Harald van Dijk @ 2022-03-11 10:12 UTC (permalink / raw)
  To: Christoph Anton Mitterer, dash

On 11/03/2022 04:25, Christoph Anton Mitterer wrote:
> Hey.
> 
> I've noted that dash gives different behaviour when both -s and -c are
> used, depending on their order:

The order is irrelevant.

> calestyo@heisenberg:~$ cat script
> date
> calestyo@heisenberg:~$
> 
> calestyo@heisenberg:~$ dash -s -c 'echo foo' script
> foo
> $     <--- this is dash's prompt, and it reads input from stdin

This has -s and -c options. Contrary to your analysis below, as has been 
answered on your Austin Group bug report, this has unspecified 
behaviour. dash can do whatever it wants here.

> calestyo@heisenberg:~$ dash -c 'echo foo' -s script
> foo

This only has a -c option. -s appears after 'echo foo', which is a 
non-option, and is therefore also a non-option. This is required to set 
$0 to -s, $1 to script, and then try to print 'foo', which dash 
correctly implements.

The syntax to have both -s and -c options, but have -s appear after -c, is

   dash -c -s 'echo foo' script

which behaves the same as the -s -c case.

Cheers,
Harald van Dijk

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: possible wrong behaviour when -s and -c are both used
  2022-03-11 10:12 ` Harald van Dijk
@ 2022-03-11 17:15   ` Christoph Anton Mitterer
  0 siblings, 0 replies; 3+ messages in thread
From: Christoph Anton Mitterer @ 2022-03-11 17:15 UTC (permalink / raw)
  To: Harald van Dijk, dash

On Fri, 2022-03-11 at 10:12 +0000, Harald van Dijk wrote:
> This has -s and -c options. Contrary to your analysis below, as has
> been 
> answered on your Austin Group bug report, this has unspecified 
> behaviour. dash can do whatever it wants here.

Well with respect to that, I'd have also been fine if the standard
clearly says that this is unspecified.


> This only has a -c option. -s appears after 'echo foo', which is a 
> non-option, and is therefore also a non-option.

Stupid me, so obvious... *facepalm*


> The syntax to have both -s and -c options, but have -s appear after -
> c, is
> 
>    dash -c -s 'echo foo' script
> 
> which behaves the same as the -s -c case.

But still (even if POSIX leaves that open)... is this intended
behaviour by dash, that one can use -s and -c and it does actually
both?

It's not directly mentioned in the manpage (i.e. that both can be used
at the same time, and in which order these would then happen).
And the SYNOPSIS in the manpage would also rather imply that it's not
intended:
> SYNOPSIS
>     dash [-aCefnuvxIimqVEbp] [+aCefnuvxIimqVEbp] [-o option_name] [+o option_name] [command_file [argument ...]]
>     dash -c [-aCefnuvxIimqVEbp] [+aCefnuvxIimqVEbp] [-o option_name] [+o option_name] command_string [command_name [argument ...]]
>     dash -s [-aCefnuvxIimqVEbp] [+aCefnuvxIimqVEbp] [-o option_name] [+o option_name] [argument ...]

So I thought maybe it's just working by accident.


Cheers,
Chris.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-11 17:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11  4:25 possible wrong behaviour when -s and -c are both used Christoph Anton Mitterer
2022-03-11 10:12 ` Harald van Dijk
2022-03-11 17:15   ` Christoph Anton Mitterer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).