Skip to contentSkip to conversation

Syntax error: Bad substitution

DISCUSSION Ralph Alvy 7 participants 17 messages Oct 28, 2006 – Nov 8, 2006

lore
Share & tools
lore

Ralph Alvy

author
#0 lore raw

I'm getting the following error when running dosemu 1.2.2 under a newly installed Kubuntu 6.10:

./xdosemu: 86: Syntax error: Bad substitution

What might be going on here?

author
#1 lore raw
Quoted 6 lines · Ralph Alvy

I'm getting the following error when running dosemu 1.2.2 under a newly installed Kubuntu 6.10:

./xdosemu: 86: Syntax error: Bad substitution

What might be going on here?

Here are the last few lines of 'strace xdosemu':

fcntl64(10, F_SETFD, FD_CLOEXEC) = 0
rt_sigaction(SIGINT, NULL, {SIG_DFL}, 8) = 0 rt_sigaction(SIGINT, {0x8054c2e, ~[RTMIN RT_1], 0}, NULL, 8) = 0 rt_sigaction(SIGQUIT, NULL, {SIG_DFL}, 8) = 0 rt_sigaction(SIGQUIT, {SIG_DFL}, NULL, 8) = 0 rt_sigaction(SIGTERM, NULL, {SIG_DFL}, 8) = 0 rt_sigaction(SIGTERM, {SIG_DFL}, NULL, 8) = 0
read(10, "#! /bin/sh\n#\n# (C) Copyright 199"..., 8192) = 8192
write(2, "./xdosemu: 86: ", 15./xdosemu: 86: ) = 15
write(2, "Syntax error: Bad substitution", 30Syntax error: Bad substitution) = 30
write(2, "\n", 1
) = 1
exit_group(2) = ?
Process 4840 detached

author
#2 lore raw
In reply to Ralph Alvy
Quoted 4 lines · Ralph Alvy

I'm getting the following error when running dosemu 1.2.2 under a newly installed Kubuntu 6.10:

./xdosemu: 86: Syntax error: Bad substitution

Just compiled 1.3.3 and have the same problem here.

#3 lore raw
In reply to Ralph Alvy

Fri, Oct 27, 2006 at 08:32:32PM -0700, Ralph Alvy may have written:

Quoted 6 lines

I'm getting the following error when running dosemu 1.2.2 under a newly installed Kubuntu 6.10:

./xdosemu: 86: Syntax error: Bad substitution

What might be going on here?

That's an error message from your shell. It doesn't like something about line 86 of the "xdosemu" shell script. What does that line of that script look like (I don't have a dosemu I can look at right now)?

To get more information, you could turn on the shell's tracing mode; for Bourne shells, you can change:

	#! /bin/sh

to

	#! /bin/sh -x

or add a "set -x" command into the script.

Matt.

Signature · 3 lines
For a successful technology, reality must take precedence over public
relations, for nature cannot be fooled.
				-- Richard P. Feynman
author
#4 lore raw
Quoted 18 lines · Matthew Clarke

Fri, Oct 27, 2006 at 08:32:32PM -0700, Ralph Alvy may have written:

Quoted 6 lines

I'm getting the following error when running dosemu 1.2.2 under a newly installed Kubuntu 6.10:

./xdosemu: 86: Syntax error: Bad substitution

What might be going on here?

That's an error message from your shell. It doesn't like something about line 86 of the "xdosemu" shell script. What does that line of that script look like (I don't have a dosemu I can look at right now)?

To get more information, you could turn on the shell's tracing mode; for Bourne shells, you can change:

#! /bin/sh

Quoted 7 lines

to

#! /bin/sh -x

or add a "set -x" command into the script.

Matt.

84 -install)
85 INSTALL=1
86 if [ -n "$2" -a "${2:0:1}" != "-" ]; then
87 PROPRIETARY=$2

This is the only distro I've seen this happen, and I use dosemu 1.2.2 under Slackware 11, Arch Current, Debian Testing, Mepis 6, and Fedora Core 5.

#5 lore raw

Sat, Oct 28, 2006 at 05:14:55PM -0700, Ralph Alvy may have written:

Quoted 10 lines
Quoted 8 lines · Matthew Clarke

Fri, Oct 27, 2006 at 08:32:32PM -0700, Ralph Alvy may have written:

Quoted 6 lines

I'm getting the following error when running dosemu 1.2.2 under a newly installed Kubuntu 6.10:

./xdosemu: 86: Syntax error: Bad substitution

What might be going on here?

[ snip ]

Quoted 4 lines

84 -install)
85 INSTALL=1
86 if [ -n "$2" -a "${2:0:1}" != "-" ]; then
87 PROPRIETARY=$2

Line 1 of the script says "#! /bin/sh", which implies that the code in the script is written in the syntax understood by the Bourne shell. However, ${2:0:1} is syntax for the GNU Bourne-again shell (AKA bash), not the Bourne shell. My guess is that your other distributions make /bin/sh a symbolic link to /bin/bash, but that Kubuntu 6.10 points /bin/sh to some other shell that understands Bourne shell syntax but not bash syntax, so the other systems hide this error in the script but Kubuntu 6.10 doesn't.

If bash is installed as /bin/bash, you can change the first line of the script to

	#! /bin/bash

to avoid the problem.

Matt.

Signature · 3 lines
For a successful technology, reality must take precedence over public
relations, for nature cannot be fooled.
				-- Richard P. Feynman
author
#6 lore raw
Quoted 28 lines · Matthew Clarke

Sat, Oct 28, 2006 at 05:14:55PM -0700, Ralph Alvy may have written:

Quoted 10 lines
Quoted 8 lines · Matthew Clarke

Fri, Oct 27, 2006 at 08:32:32PM -0700, Ralph Alvy may have written:

Quoted 6 lines

I'm getting the following error when running dosemu 1.2.2 under a newly installed Kubuntu 6.10:

./xdosemu: 86: Syntax error: Bad substitution

What might be going on here?

[ snip ]

Quoted 4 lines

84 -install)
85 INSTALL=1
86 if [ -n "$2" -a "${2:0:1}" != "-" ]; then
87 PROPRIETARY=$2

Line 1 of the script says "#! /bin/sh", which implies that the code in the script is written in the syntax understood by the Bourne shell. However, ${2:0:1} is syntax for the GNU Bourne-again shell (AKA bash), not the Bourne shell. My guess is that your other distributions make /bin/sh a symbolic link to /bin/bash, but that Kubuntu 6.10 points /bin/sh to some other shell that understands Bourne shell syntax but not bash syntax, so the other systems hide this error in the script but Kubuntu 6.10 doesn't.

Quoted 8 lines

If bash is installed as /bin/bash, you can change the first line of the script to

#! /bin/bash

to avoid the problem.

Matt.

Thanks, Matt. This solved it nicely.

#7 lore raw
In reply to Matthew Clarke
Quoted 7 lines · Matthew Clarke

Sat, Oct 28, 2006 at 05:14:55PM -0700, Ralph Alvy may have written:

Quoted 4 lines

84 -install)
85 INSTALL=1
86 if [ -n "$2" -a "${2:0:1}" != "-" ]; then
87 PROPRIETARY=$2

Quoted 6 lines

If bash is installed as /bin/bash, you can change the first line of the script to

        #! /bin/bash

to avoid the problem.

You could also replace line 86 by:

           if [ -n "$2" -a -n "${2%%-*}" ]; then

which is portable to Bourne sh AFAIK (and a better solution for dosemu itself -- some distributions don't like /bin/bash scripts).

Bart

author
#8 lore raw
Quoted 11 lines · Bart Oldeman
Quoted 10 lines · Matthew Clarke

Sat, Oct 28, 2006 at 05:14:55PM -0700, Ralph Alvy may have written:

Quoted 4 lines

84 -install)
85 INSTALL=1
86 if [ -n "$2" -a "${2:0:1}" != "-" ]; then
87 PROPRIETARY=$2

If bash is installed as /bin/bash, you can change the first line of the script to

Quoted 8 lines
Quoted 3 lines
        #! /bin/bash

to avoid the problem.

You could also replace line 86 by:

            if [ -n "$2" -a -n "${2%%-*}" ]; then

which is portable to Bourne sh AFAIK (and a better solution for dosemu itself -- some distributions don't like /bin/bash scripts).

Well, for me anyway, I think it's easier to remember to change the first line to

        #! /bin/bash

whenever I see this problem arise, which is so rare to begin with (only one disribution so far, among so many installed).

author
#9 lore raw
In reply to Bart Oldeman
Quoted 1 line · Bart Oldeman

if [ -n "$2" -a -n "${2%%-*}" ]; then

I tried your substitution under Kubuntu 6.10. Two comments:

1. There's one more instance where the substitution must be made: line 98.

2. xdosemu loads fine, though there is one error message upon loading:

        [: 373: 0: unexpected operator
#10 lore raw
Quoted 11 lines · Ralph Alvy
Quoted 1 line · Bart Oldeman

if [ -n "$2" -a -n "${2%%-*}" ]; then

I tried your substitution under Kubuntu 6.10. Two comments:

1. There's one more instance where the substitution must be made: line 98.

2. xdosemu loads fine, though there is one error message upon loading:

        [: 373: 0: unexpected operator

[...]

That is because the new Ubuntu release uses dash instead of bash for /bin/sh and hence all bash constructs are not supported.

Signature · 1 line
mitu
#11 lore raw
Quoted 10 lines · Cristi Mitrana
Quoted 9 lines · Ralph Alvy
Quoted 1 line · Bart Oldeman

if [ -n "$2" -a -n "${2%%-*}" ]; then

I tried your substitution under Kubuntu 6.10. Two comments:

1. There's one more instance where the substitution must be made: line 98.

Quoted 9 lines
Quoted 3 lines

2. xdosemu loads fine, though there is one error message upon loading:

        [: 373: 0: unexpected operator

[...]

That is because the new Ubuntu release uses dash instead of bash for /bin/sh and hence all bash constructs are not supported.

Isn't that a rather severe change?

#12 lore raw
Quoted 1 line · Ralph Alvy

Cristi Mitrana wrote:

[..]

Quoted 6 lines
Quoted 4 lines

That is because the new Ubuntu release uses dash instead of bash for /bin/sh and hence all bash constructs are not supported.

Isn't that a rather severe change?

It is actually, since dash is just a minimal POSIX shell without all the features that bash has it.
Any script that uses bash constructs should have #!/bin/bash at the beginning instead of #!/bin/sh. It's more of an annoyance this days, at least on linux, because bash is always available in any distro and it is the default shell.

Signature · 1 line
mitu
#13 lore raw
Quoted 13 lines · Cristi Mitrana
Quoted 1 line · Ralph Alvy

Cristi Mitrana wrote:

[..]

Quoted 6 lines
Quoted 4 lines

That is because the new Ubuntu release uses dash instead of bash for /bin/sh and hence all bash constructs are not supported.

Isn't that a rather severe change?

Quoted 6 lines

It is actually, since dash is just a minimal POSIX shell without all the features that bash has it.
Any script that uses bash constructs should have #!/bin/bash at the beginning instead of #!/bin/sh. It's more of an annoyance this days, at least on linux, because bash is always available in any distro and it is the default shell.

Umm, I believe that all current releases of Linux have

$ ls -l /bin/sh
lrwxrwxrwx  1 root root 4 Oct 20  2004 /bin/sh -> bash

AND bash also behaves somewhat differently when invoked as sh.

IMO, use of bash-specific features in released scripts is a bad idea, anyway. It results in extra maintenance.

Mike

Signature · 5 lines
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
author
#14 lore raw
In reply to Ralph Alvy
Quoted 6 lines · Ralph Alvy

I'm getting the following error when running dosemu 1.2.2 under a newly installed Kubuntu 6.10:

./xdosemu: 86: Syntax error: Bad substitution

What might be going on here?

I noticed this comment on a Web page about compiling kernels with Ubuntu 6.10 (http://www.howtoforge.com/kernel_compilation_ubuntu). Pretty much sums up the problems outlined in this thread:

--- quote follows ---

On Ubuntu 6.10, /bin/sh is a symlink to /bin/dash by default. /bin/dash seems to make problems when you compile software from the sources, at least I had that impression. That's why I make /bin/sh a symlink to /bin/bash instead.

If you are on Ubuntu 6.10, you should do this now:

rm -f /bin/sh
ln -s /bin/bash /bin/sh

#15 lore raw
Quoted 7 lines · Ralph Alvy

--- quote follows ---

If you are on Ubuntu 6.10, you should do this now:

rm -f /bin/sh
ln -s /bin/bash /bin/sh

There are still advantages in using dash over bash, e.g. scripts are executed faster that way. As for the remaining dosemu warning you got, replacing
$UID
by
id -ur
in the dosemu script should fix that.

Bart

author
#16 lore raw
Quoted 18 lines · Bart Oldeman
Quoted 7 lines · Ralph Alvy

--- quote follows ---

If you are on Ubuntu 6.10, you should do this now:

rm -f /bin/sh
ln -s /bin/bash /bin/sh

There are still advantages in using dash over bash, e.g. scripts are executed faster that way. As for the remaining dosemu warning you got, replacing
$UID
by
id -ur
in the dosemu script should fix that.

Quoted 1 line

Bart

I ended up just replacing

        #! /bin/sh

with

        #! /bin/bash

Seemed like the easiest thing to do.