ash: command line editing question

Alexander Griesser alexander.griesser at lkh-vil.or.at
Thu Dec 6 08:21:05 UTC 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Loïc Grenié wrote:
>> Basically, this happens with all unfinished commands, the
>> calculation above was just mentioned because it happened
>> to me while I was working on a formula to calculate battery
>> lifetime indicators.
>>
> 
>    One ) is probably considered part of the fomula (even though the
>   formula will result sintactically incorrect) while one )) ends the
>   formula.

That sounds reasonable, but I tried `dash` today (busybox ash seems to
behave similar than dash in most things) and dash does the following:

- ------------------------[ dash ] -----------------------
$ VAR=2
$ echo $(( $VAR + $VAR ))
4
$ echo $(( $VAR + $VAR )
> )
> )
>
$
- ---------------------------------------------------------

As you can see, the first try works because I did everything right, in
the second try I "forgot" to add the last parantheses and the '>' prompt
appears.

dash behaves similar than ash in that it doesn't let me finish this
command by simply adding the missing parantheses in the next line which
is perfectly fine (I don't demand that it should work like this), _BUT_
(and that's the big difference) dash lets me exit this editing mode by
simply hitting CTRL-C as you can see in the last line of the above
output.

Again, busybox ash doesn't do this, but I found out another interesting
thing. bash, dash and ash seem to act very differently wrt arithmetic
parsing:

- -------------------------[ bash ]---------------------------
$ VAR=2
$ echo $(( $VAR + $VAR )
> ))
bash: syntax error near unexpected token `)'
$ echo $(( $VAR + $VAR )
> )
bash: 2: command not found
$
- -------------------------------------------------------------
There's no obvious way to let the arith complete successfully.

- -------------------------[ dash ] ---------------------------
$ VAR=2
$ echo $(( $VAR + $VAR )
> )
> [CTRL-C]
$ echo $(( $VAR + $VAR )
> ))
4
$
- --------------------------------------------------------------
One single paren doesn't help, but two parens let the arith
complete successfully and will bring me back to the shell prompt.

- -------------------------[ busybox ash ]----------------------
$ VAR=2
$ echo $(( $VAR + $VAR)
> )
> ))
ash: syntax error:  2 + 2 )

$
- --------------------------------------------------------------
No reaction on a single paren in the second line, but a double
closing paren seems to do what dash does, but the arith itself
throws a syntax error afterwards.

So, what's the desired behaviour?

ciao,
- --
Alexander Griesser (Netzwerkadministration)
E-Mail: alexander.griesser at lkh-vil.or.at | Web: http://www.lkh-vil.or.at
KABEG LKH Villach | Nikolaigasse 43 | 9500 Villach
Tel.:   +43 4242 208 3061 | Fax.:   +43 4242 971 3061
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHV7Dx66HVD6KUm1oRAnOkAJ9vEPY91pQ2mFVCvSVlYkPqP3Hw/QCgo+d1
j9xATMo71mZfOvIc17gtHTs=
=JiLZ
-----END PGP SIGNATURE-----



More information about the busybox mailing list