cc: Maureen.Chew at Sun.COM
Subject: Re: [shell-discuss] /bin/sh eval difference
--------
> d.sh
> ----
> #!/bin/sh
> copynum=1
> foo="`eval "$"{copy$copynum"+0}"`"
>
> -----
>
> on solaris 10:
> javabean. sh -x d.sh
> copynum=1
> + eval ${copy1+0}
> foo=
>
>
> on opensolaris:
> maureen at opensolaris:~# sh -x d.sh
> + copynum=1
> + eval '{copy1+0}'
> + '{copy1+0}'
> d.sh[3]: eval[1]: {copy1+0}: not found [No such file or directory]
> + foo=''
This is a documented difference between ksh88 and ksh93 (although
the first report of an actual difference). You are relying on
unspecified behavior in POSIX.
ksh
foo="`eval "$"{copy$copynum"+0}"`"
I read as the concatination of three parts:
"`eval " $ $"{copy$copynum"+0}"`"
The behavior of $"..." is unspecified by posix but is equivalent
to "..." in ksh93 except that this string is marked for localization.
This is how you internationalize shell scripts.
Now for compatibility, I could disable this check within `...` since
using $(...) instead of `...` is hightly prefered.
Thanks for reporting this problem.
The following should work for both shell
foo="`eval \\\${copy$copynum+0}`"
However the correct way to write this is
eval foo=$(\${copy$copynum+0})
David Korn
dgk at research.att.com