tags:

views:

350

answers:

2

I have a ksh script that has to remain so (some of the programs it runs insist on being ksh). I want to take the input argument "test.txt" and remove the last 4 characters or find and replace the ".txt" with nothing.

In bash I would do

NewVar=${@/.txt/}

This doesn't work in ksh though. How can I get rid of the .txt in ksh? I tried

bash -c 'NewVar=${@/.txt/}'

but it didn't work the $@ variable into this newly created shell.

Thanks,

Dan

+4  A: 

Why not use basename?

toolkit
+1, you nailed it :)
dwc
A: 

ksh won't let you do it with $@, but if you assign it to a temporary variable, you can do it without spawning another proc with

tmp=$@
newvar=${tmp%.txt}
Charlie