Shell tricks (was: [TxMt] Xetex)

Allan Odgaard allan at macromates.com
Tue Apr 12 14:00:21 UTC 2005


On Apr 11, 2005, at 17:34, Alain Matthes wrote:

> echo $TM_FILEPATH | perl -e 'while(<>){s/\.tex$/.pdf/;print;}' | xargs

I generally avoid commenting on code unless I'm asked, but here's a few 
tips which I think will be useful in a lot of TM-related shell scripts, 
don't take it personal that this was triggered by your script! :)

The shell is capable of doing replacements in variables. There's a few 
different forms, for this one, one can do: 
${variable%suffix_to_remove}, e.g.:

    ${TM_FILEPATH%.tex}.pdf

Another form is (for single replacement): ${variable/search/replace} 
and to replace all instances it's: ${variable//search/replace}.

Another neat thing is that we can set stdin for a command to a string 
using <<<, for example:

    perl <<<$TM_FILEPATH -pe 's/\.tex$/.pdf/' | xargs

Kind regards Allan




More information about the textmate mailing list