1

When I work under tcl environment, once I cd to a directory, even if the path I specify is its symbolic link, then no matter whether I run pwd -L or pwd -P, they all return the absolute path. This is troublesome for me because I try to replace a user-specific workspace path with a variable name so that when different user execute the script, they will switch to their own workspace. However, the system $::env(WORK) returns the symbolic link of the path while pwd command returns the absolute path, so that I cannot do an sed command.

For example,

stcl> cd $::env(WORK)
stcl> puts [format "cd %s" [exec echo [pwd] | sed "s,$::env(WORK),\$WORK,g"]]

What I want the code to do is to print "cd $WORK", but because pwd returns absolute path, even if I use pwd -L, I cannot get a match with sed command and therefore cannot replace the string.

1 Answer 1

1

Doesn't look like Tcl gives you any control over cd and pwd.

An alternative: resolve the symbolic links in the WORK env var, and compare that to pwd:

format {cd "%s"} [expr {[pwd] eq [file normalize $::env(WORK)] ? {$WORK} : [pwd]}]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .