[plug] string manipulation

Bruce M. Axtens bruce.axtens at gmail.com
Sat Apr 22 19:28:28 WST 2006


Okay, based on what you originally asked for
>>>> This is what works at the mo:   temp=${what_i_am_looking_for%/*}
>>>>                                              newVar=${temp##*/}
>>>
>>>> What I was trying to do was combine both:
>>>> newVar=${${what_i_am_looking_for%/*}##*/}

and presupposing that I understand the issue, translating the "what 
works at the moment" version into Tcl is
	set temp [file normalize $what_i_am_looking_for]
	set newVar [file dirname $temp]
These could be merged as
	set newVar [file dirname [file normalize $what_i_am_looking_for]]

The blurb on file normalize is below. Because I don't know bash very 
well (at all) I had to make a few guesses about what the % and ## were 
all about.

As for Bernie's suggestion

>> for ff in $var ; do
>>   parent=`dirname \`dirname $ff\``
>>   # do stuff in the $parent
>> done

that could be done in Tcl (assuming var is a list ... different syntax 
otherwise) as
	foreach ff $var {
		set parent [file dirname [file dirname $ff]]
		# do stuff in the $parent
	}

Again, I'm not entirely sure what's wanting to be achieved.

Regards,
Bruce.

file normalize name
         Returns a unique normalised path representation for the 
file-system object (file, directory, link, etc), whose string value can 
be used as a unique identifier for it. A normalized path is an absolute 
path which has all '../', './' removed. Also it is one which is in the 
``standard'' format for the native platform. On MacOS, Unix, this means 
the segments leading up to the path must be free of symbolic 
links/aliases (but the very last path component may be a symbolic 
link), and on Windows it also means means we want the long form with 
that form's case-dependence (which gives us a unique, case-dependent 
path). The one exception concerning the last link in the path is 
necessary, because Tcl or the user may wish to operate on the actual 
symbolic link itself (for example 'file delete', 'file rename', 'file 
copy' are defined to operate on symbolic links, not on the things that 
they point to).

On Saturday, April 22, 2006, at 06:58  PM, Craig Dyke wrote:




More information about the plug mailing list