• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

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
0
bcarlis
Asked:
bcarlis
  • 4
1 Solution
 
nemws1Commented:
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
 
nemws1Commented:
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
 
bcarlisAuthor 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
 
nemws1Commented:
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
 
nemws1Commented:
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

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now