Setting environment variable - KSH vs Bash?

Hi,
I was told to set this variable and then run a shell script..

$XXAPX_TOP=/home/oravess11
$export XXAPX_TOP
$echo $XXAPX_TOP
   /home/oravess11            - should be output

the shell script is KSH and I believe mine is Bash?

I had to drop the $
$XXAPX_TOP=/home/oravess11

Had to drop the the whole export statement also
$export XXAPX_TOP


XXAPX_TOP=/home/oravess11
$echo $XXAPX_TOP
-bash: /home/oravess11: is a directory

But it did not assign it

02:55:11 PM > +-------------------------------------------------------------------------------------+
02:55:11 PM > | Verifying CUSTOM_TOP Directories Exist                                              |
02:55:11 PM > +-------------------------------------------------------------------------------------+
02:55:11 PM >  DOES NOT EXIST

I am not very up on my shell environment... what should I do?

Thanks, Bill
LVL 2
BILL CarlisleAPEX DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nemws1Database AdministratorCommented:
You need to export XXAPX_TOP in order for a sub-process to see it.

Just like in programming, if you do this:

a=5

In BASH, only the current process will see that variable.  If you run another script, that 'bash' will be a *child* of the current 'bash' and will only see "export"ed vars.

What you want is the following, with no dollar signs.

export XXAPX_TOP=/home/oravess11

Open in new window

0
nemws1Database AdministratorCommented:
If you were using KSH (which I think is unlikely), I believe the same statement would work.  If you are running just /bin/sh, you have to separate them out, but still no dollar signs on the vars:

XXAPX_TOP=/home/oravess11
export XXAPT_TOP

Open in new window

0
BILL CarlisleAPEX DeveloperAuthor Commented:
Thank you, how would I code it to handle Kch, Bash, Csh

is there a way to program it to see what shell you are in, then execute the proper syntax?

thx, Bill
0
nemws1Database AdministratorCommented:
I've already given you ksh and bash.  Almost nobody uses csh anymore.  If you asked 10 years ago, maybe I'd come up with something.

The default is to program for /bin/sh (ie the 2-step export that I posted above).  Every UNIX system should have /bin/sh.

You can look at the environment variable $SHELL to see the shell that is currently in use.
0
nemws1Database AdministratorCommented:
You might want to pose the question of a "universal" script as a new question.  It doesn't have much to do with your original question (which doesn't mention 'csh' at all).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.