[TxMt] Req: Compare docs-Diff

Allan Odgaard allan at macromates.com
Mon Feb 21 11:03:20 UTC 2005


On Feb 19, 2005, at 23:15, Sune Foldager wrote:

>>> I don't get it; this is expected behaviour, no?
>> Did you read Eric's post? Do you know how we can solve this problem 
>> w/o using xargs?
> Oh.. we can't. The quotes are taken as part of the name, since bash 
> doesn't do any further processing on expanded variables. Thus, unless 
> fed to an argument splitter like xargs, quotes strings in variables 
> are not very useful. An alternative *could* be to use bash array 
> env-vars. I don't know how you can manipulate those though :-p.

Just found the “solution”, we can convert TM_SELECTED_FILES to an array 
using eval, example:
    eval FILES=($TM_SELECTED_FILES)
    for ((i=0; i < ${#FILES[@]}; i++)); do
       ls -l "${FILES[i]}"
    done

Or as required in the original example:
    eval FILES=($TM_SELECTED_FILES)
    diff -u "${FILES[0]}" "${FILES[1]}"

Though generally the xargs version is nicer, and also, it would work if 
the file names contained quotes, which the above doesn't take care of.

And should you want to use the above, you may want to set the input 
field separator (IFS) to just a space (by default it also contains tab 
and newline) -- not that I really expect anyone to find this useful, 
but at least it seems there is a solution which doesn't involve an 
argument splitter like xargs.




More information about the textmate mailing list