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
rohit_shinez:
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
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
rbatte1
December 15, 2016, 6:48am
4
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