When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found"

My code is as follows:

#!/bin/sh
user="test"
DIR="/bldtmp/"$user
VIEW="test.view1"
echo "TMPDIR before export :"$TMPDIR
MY_CMD='/usr/atria/bin/cleartool setview -exec "export TMPDIR='$DIR'/tmp;export UNPACKDIR='$TMPDIR'/unpackdir;echo After Export: $TMPDIR " '$VIEW
echo "cmd : " $MY_CMD
eval $MY_CMD

output coming :

TMPDIR before export :/var/tmp
cmd :  /usr/atria/bin/cleartool setview -exec "export TMPDIR=/bldtmp/test/tmp;export UNPACKDIR=/var/tmp/unpackdir;echo After Export: $TMPDIR " test.view1
export: Command not found.
Exit 1
export: Command not found.
Exit 1
After Export: /var/tmp

If i am directly specifying the export command inside the shell script, it is working, but when i am trying it through "/usr/atria/bin/cleartool setview -exec "export TMPDIR=/bldtmp/test/tmp;export UNPACKDIR=/var/tmp/unpackdir;echo After Export: $TMPDIR " test.view1" it is not working.

my shell version is:

GNU bash, version 3.00.15(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.

Please help me on this.

Thanks

It is rarely a good idea to store a command and its arguments in a variable. Use a function instead.

Let's lose all the surplus Shell syntax, remove, move, or correct many quote characaters, and just execute the command.
There is an issue with $TMPDIR because the value can only come from the login script. Let's assume that it has a value, otherwise every line mentioning $TMPDIR will fail.
I have no idea what is in /usr/atria/bin/cleartool but there is no possible way that a called process executed in this manner can change the environment of the calling process.

#!/bin/sh
user="test"
DIR="/bldtmp/$user"
VIEW="test.view1"
echo "TMPDIR before export : $TMPDIR"
/usr/atria/bin/cleartool setview -exec "export TMPDIR=$DIR/tmp"
export UNPACKDIR="$TMPDIR/unpackdir"
echo "After Export: $TMPDIR  $VIEW"

Assuming that /usr/atria/bin/cleartool is a Shell Script, it would need to execute in the current Shell environment if it was to change the current Shell environment.

Perhaps:

. ./usr/atria/bin/cleartool

i.e dot-space-dot-slash-scriptname

I used to use clearcase in my last organization (back in 2005) . Its a software configuration management tool from IBM for maintaining source-code etc.

@dchoudhury,

There might be lots of newer versions released from that time but I remember, the said command was used to set the particular view (provided by view-tag, which is not present in your command).
i.e

cleartool set_view view_tag

You can also run your start-up files (containing the export command and other environment) with the -login option.

cleartool setview -login view-tag

In every case you have to provide the dynamic view-tag.

You might want to look at this link

@clx

i used:

"cleartool setview -exec "cmds to execute" <dynamic view_name> ".

This command used to execute some commands within a view after setting the dynamic view. The above command will first set the view and then it will executes the commands provided.

So i tried to execute export command here, to override the default value, which is failing.

---------- Post updated at 10:43 AM ---------- Previous update was at 10:40 AM ----------

@methyl

"cleartool setview -exec "cmds to execute" viewname"

is clearcase command used inside a clearcase view to execute the cmds within a view after setting it.

/usr/atria/bin/cleartool is the path of the clearcase installed in the system.

thanks