resolve the setting into a view from a shell script does not process the remaining commands in the script issue

When running the sample script below, all commands executed after the cleartool setview command are not processed because cleartool setview spawns a new shell:


#!/bin/sh
/usr/atria/bin/cleartool setview cmview
/usr/atria/bin/cleartool pwv
/usr/atria/bin/cleartool lsview
cd /vob/transition/Admin_transition
/usr/atria/bin/cleartool mkbrtype -global -nc 02b456

In the above script any commands that appear after the execution of cleartool setview cmview are not processed because a shell is spawned off with exec(), which replaces the current program with a new program.

This means current process's text and code segments, which in this case is the script that contains all the commands, is replaced by the program getting executed, which is the shell invoked by running cleartool setview cmview. Hence, none of the commands are processed beyond the point of invocation of the setview.

WORKAROUNDS:

1. Run cleartool setview prior to calling the script
or

2. Run the cleartool setview command and exec into the script

FAQ:

Q: How does setview select the subshell (csh, sh, ksh, bash ...) to spawn?

When cleartool setview is run, a new shell will be spawned. The shell chosen will depend on your default shell as defined in your NIS maps or your local /etc/passwd file.

You can verify your default shell as follows.

For NIS:
ypcat passwd | grep

For local passwd file:
grep /etc/passwd

The default shell is the last entry on the line.

For example:
$ ypcat passwd | grep jdoe
jdoe:sbe.p46JQm9kE:20147:5089:John Doe:/people/jdoe:/bin/bash


This example shows that the Bash Shell is the default shell (
/bin/bash).


Q: How do I override the default shell?

One way of overriding the default shell chosen by cleartool is to use the $SHELL environment variable.

Using the above example, even though the default shell is
/bin/bash, you can change the shell that cleartool uses by running:

$ setenv SHELL /bin/ksh
$ setenv | grep SHELL
SHELL=/bin/ksh


Now when cleartool is run, the Korn Shell (ksh) will be spawned, and not bash.


Q: How can I avoid losing my shell environment after setting into a view?

When running cleartool setview while logged in as a user whose default shell is ksh, the ksh environment is not picked up. Why?

In this setup, spawning a shell executes .profile but does not execute .kshrc. To be able to use the environment you have setup in .kshrc, add the following lines to your .profile:

ENV=$HOME/.kshrc
export ENV


The ENV command forces it to run .kshrc as well.

The export command forces the shell to pass that value onto the setview subshell, thereby setting up the environment.

Note: Review the man pages for the other shells to determine the files to edit following the concepts above.

No comments:

Post a Comment