1

I want to find the parent of a checked out file in ClearCase from a Bash script. For example, if I type ct ls I get this:

$ ct ls some_file
some_file@@/main/some/branch/CHECKEDOUT from some_file@@/main/some/branch/6   Rule: CHECKEDOUT

I want to find the parent version (some_file@@/main/some/branch/6) from a script. Sure I can use awk or similar text processing tools, but I think that's a very ugly solution, and can easily break for more exotic file names (for example if it has spaces or the string "from" in it).

petersohn
  • 11,292
  • 13
  • 61
  • 98

1 Answers1

0

Use the "%PSn" format of fmt_ccase (cleartool describe)

 cleartool describe -fmt "%PSn" some_file@@/main/some/branch/CHECKEDOUT

 %PSn

Predecessor Short name:
For a version, a short form of the predecessor version's version ID: branch-pathname/version-number.
For other objects, the null string.

Note that for @@/main/0 (which all elements, files or directories, have), it will also return a null string.


The OP petersohn mentions that it is similar to:

cleartool describe -short -pred some_file@@/main/some/branch/CHECKEDOUT
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks. Actually, I found out that `cleartool describe -short -pred some_file@@/main/some/branch/CHECKEDOUT` works just as well. There is also a lot of useful stuff here: http://stackoverflow.com/questions/4447178/script-to-get-a-files-version-in-clearcase – petersohn Dec 07 '12 at 15:54
  • @petersohn Interesting. I have including your command in the answer for more visibility. – VonC Dec 07 '12 at 15:55