* sed script fails to run in dash
@ 2013-11-22 18:11 Tormen
2013-11-22 19:20 ` Seb
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Tormen @ 2013-11-22 18:11 UTC (permalink / raw)
To: dash
Hi,
I am puzzled and don't know why this command does not work with dash (I
am currently using the debian stable (v7.2) version of dash (v0.5.7-3)):
echo 1>/tmp/x; reponse=$( sed -e $(wc -l </tmp/x)$'{w/dev/stdout\n;d}'
-i /tmp/x ); echo "reponse='$reponse'"
but also just this line:
sed -e 1$'{w/dev/stdout\n;d}' -i /tmp/x
in a dash script will yield the error message:
sed: -e expression #1, char 2: unknown command: `$'
But why ? :(
I would be really grateful for any explanation.
Thanks a lot in advance for any hint!
Tormen
P.S.: The source for the above line is:
http://stackoverflow.com/questions/13804967/bash-pop-lines-in-a-file
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sed script fails to run in dash
2013-11-22 18:11 sed script fails to run in dash Tormen
@ 2013-11-22 19:20 ` Seb
2013-11-22 19:25 ` Jonathan Nieder
2013-11-22 19:26 ` Eric Blake
2 siblings, 0 replies; 5+ messages in thread
From: Seb @ 2013-11-22 19:20 UTC (permalink / raw)
To: Tormen; +Cc: dash
Le Fri, 22 Nov 2013 19:11:42 +0100
Tormen a écrit:
Hello,
> but also just this line:
>
> sed -e 1$'{w/dev/stdout\n;d}' -i /tmp/x
>
> in a dash script will yield the error message:
>
> sed: -e expression #1, char 2: unknown command: `$'
>
> But why ? :(
It seems dash strictly passes what you have given and which is
sed-speaking incorrect:
$ dash -c "strace sed -e 1$'{w/dev/stdout\n;d}' -i /tmp/x"
execve("/usr/bin/sed", ["sed", "-e", "1${w/dev/stdout\\n;d}", ...
^^^
Bash does not, and so passes something sed understands:
$ bash -c "strace sed -e 1$'{w/dev/stdout\n;d}' -i /tmp/x"
execve("/usr/bin/sed", ["sed", "-e", "1{w/dev/stdout \n;d}", ...
^^^
If you escape the "$" with bash, you will get your kitten back:
$ bash -c "sed -e 1\\$'{w/dev/stdout\n;d}' -i /tmp/x"
sed: -e expression #1, char 2: unknown command: `$'
Take care,
Seb.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sed script fails to run in dash
2013-11-22 18:11 sed script fails to run in dash Tormen
2013-11-22 19:20 ` Seb
@ 2013-11-22 19:25 ` Jonathan Nieder
2013-11-22 19:26 ` Eric Blake
2 siblings, 0 replies; 5+ messages in thread
From: Jonathan Nieder @ 2013-11-22 19:25 UTC (permalink / raw)
To: Tormen; +Cc: dash
Hi Tormen,
Tormen wrote:
> sed -e 1$'{w/dev/stdout\n;d}' -i /tmp/x
>
> in a dash script will yield the error message:
>
> sed: -e expression #1, char 2: unknown command: `$'
>
> But why ? :(
POSIX sayeth[1]:
The '$' character is used to introduce parameter expansion, command
substitution, or arithmetic evaluation. If an unquoted '$' is
followed by a character that is not one of the following:
* A numeric character
* The name of one of the special parameters (see 2.5.2 Special
Parameters)
* A valid first character of a variable name
* A <left-curly-bracket> ( '{' )
* A <left-parenthesis>
the result is unspecified.
A single-quote is not the name of a special parameter nor valid as the
first character of a variable name, so this is unspecified behavior
and should be avoided in scripts meant to run on an arbitrary POSIX
shell.
However the next major version of POSIX is likely to mandate support
for $'' string handling[2]. Work towards an implementation in dash would
be very welcome.
Thanks and hope that helps,
Jonathan
[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06
[2] http://austingroupbugs.net/view.php?id=249
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sed script fails to run in dash
2013-11-22 18:11 sed script fails to run in dash Tormen
2013-11-22 19:20 ` Seb
2013-11-22 19:25 ` Jonathan Nieder
@ 2013-11-22 19:26 ` Eric Blake
2013-11-23 0:14 ` Tormen
2 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2013-11-22 19:26 UTC (permalink / raw)
To: Tormen, dash
[-- Attachment #1: Type: text/plain, Size: 499 bytes --]
On 11/22/2013 11:11 AM, Tormen wrote:
> sed -e 1$'{w/dev/stdout\n;d}' -i /tmp/x
>
> in a dash script will yield the error message:
>
> sed: -e expression #1, char 2: unknown command: `$'
>
> But why ? :(
Because $'' is not (yet) in POSIX. It will be required in a future
release, but dash hasn't implemented it yet.
http://austingroupbugs.net/view.php?id=249
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sed script fails to run in dash
2013-11-22 19:26 ` Eric Blake
@ 2013-11-23 0:14 ` Tormen
0 siblings, 0 replies; 5+ messages in thread
From: Tormen @ 2013-11-23 0:14 UTC (permalink / raw)
To: Eric Blake; +Cc: dash
On 22/11/13 20:26, Eric Blake wrote:
> On 11/22/2013 11:11 AM, Tormen wrote:
>
>> sed -e 1$'{w/dev/stdout\n;d}' -i /tmp/x
>>
>> in a dash script will yield the error message:
>>
>> sed: -e expression #1, char 2: unknown command: `$'
>>
>> But why ? :(
> Because $'' is not (yet) in POSIX. It will be required in a future
> release, but dash hasn't implemented it yet.
>
> http://austingroupbugs.net/view.php?id=249
Now I get how this script works ;)
Thanks !! :)
!!! And also thanks to all the other answers !!! - really appreciated! :)))
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-11-23 0:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-22 18:11 sed script fails to run in dash Tormen
2013-11-22 19:20 ` Seb
2013-11-22 19:25 ` Jonathan Nieder
2013-11-22 19:26 ` Eric Blake
2013-11-23 0:14 ` Tormen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox