bad substitution Error while renaming Extension

Hi All,

We are in the process of Migrating from AIX 4 to Solaris 10 and getting a Few Errors.

I have been programming in shell but could never establish muself as an expert, hence please need you help.

I am Getting Bad Substitution error in my script, I have isolated the issue and its illustrated as below

$ FILENAME=TEST_FILE.txt
$ echo $FILENAME
TEST_FILE.txt
$ echo ${FILENAME%.txt}
bad substitution
$

But the above Works absolutely fine in my AIX environment (below)

$ FILENAME=TEST_FILE.txt
$ echo $FILENAME
TEST_FILE.txt
$ echo ${FILENAME%.txt}
TEST_FILE
$

How can i get this working in Solaris, One thing i noticed is that the Default Shell in My AIX is Korn and in Solaris is Bourn
I tried setting the SHELL variable to Korn in my Solaris machine by setting SHELL=/usr/bin/ksh
but still the same result.

P.s. the above is just an Example, the Shell script uses the ${..........} for much advanced conversions:

Please Help.

Hi.

Setting the SHELL variable in this way will not change your shell. Your script should have #!/usr/bin/ksh in the first line.

The substitution should work fine in Solaris 10 (it does in KSH on Solaris 8 where I just tested it):

# uname -a
SunOS laberv12 5.8 Generic_108528-15 sun4u sparc SUNW,UltraAX-i2
# echo $0
-ksh
# FILENAME=TEST_FILE.txt
# echo ${FILENAME%.txt}
TEST_FILE

?

s99:/export/home/vbe $ FILENAME=TEST_FILE.txt
s99:/export/home/vbe $  echo $FILENAME
TEST_FILE.txt
s99:/export/home/vbe $ echo ${FILENAME%.txt}
TEST_FILE
s99:/export/home/vbe $ uname -r
5.10
s99:/export/home/vbe $ echo $SHELL
/usr/bin/ksh
s99:/export/home/vbe $ 

What shell are you using?

I guess the default Shell is Bourn

$ echo $0
-sh

as suggested in one of the above posts i did create a shell script and add #!/usr/bin/ksh to the first line (See below)

$ uname -a
SunOS m5k604d1 5.10 Generic_139555-08 sun4u sparc SUNW,SPARC-Enterprise
$ echo $0
-sh
$ cat ren_files.sh
#!/usr/bin/ksh
set -a

FILENAME=TEST_FILE.txt
echo ${FILENAME%.txt}

set +a

$ sh ren_files.sh
ren_files.sh: bad substitution
$

Not Sure whats wrong out here.

Hi.

Running the script as:

$ sh ren_files.sh

will override the #!/usr/bin/ksh in your script, and run the script with sh.

Run the script as

./ren_files.sh

or even

ksh ren_files.sh

If you do sh ren_files.sh, then the shebang line gets ignored and the script is run with sh.
Modify the script to be executable and call script like ./ren_files.sh then.

That Did it

./ren_files.sh

works as expected.

Thanks a Ton!!