Change file extension

Hi Guys,

i am trying to redirect a file wherein i need to change the extension of the file from .sh to .tmp, but getting an error

a=test.txt

sh test.txt > path/$(basename "$a" .sh).tmp

i need 
test.tmp

---------- Post updated at 02:09 AM ---------- Previous update was at 01:52 AM ----------

Guys it worked for me

You say you're trying to change .sh in test.txt to .tmp ??? But there is no .sh in test.txt . Do you want to change .txt to .tmp ? Or, did you intend to set a=test.sh instead of test.txt ?

Yes you are correct its .txt to .tmp

Using variable substitution, you can do this in ksh/bash:-

a=test.txt
b="${a%.txt}.tmp"        # Removes the .txt then appends .tmp

sh test.txt > path/$b

As an alternate, could you do this?:-

a=test

sh $a.txt > path/$a.tmp

Robin