not able to execute script

hi,
I have 2 questions

Ques1.) I have one script(profile.ksh) and I execting it by
# ./profile.ksh
./profile.ksh: bad substitution

and when I am using
ksh profile.ksh ----it is running.
but other scripts are running fine.

So can any1 tell me what is wrong with it :confused:

Ques2.) in profile.ksh I want to set some envirnment variable but I am not able to set it

I am writing some variables which I have to set

COMMON_USER_HOME=${HOME}
export COMMON_USER_HOME
echo COMMON_USER_HOME=$COMMON_USER_HOME

export P4USER="AbcdeF"
echo P4USER=$P4USER

but when I am running my file profile.ksh and echoing the variable then I am able to see the output of the variables:

# echo $SHELL
/bin/sh

COMMOM_USER_HOME=/home/User1
P4USER=AbcdeF

but not able to see it as exported when using set commond :confused:

For 1) try having the first line in the script like:

#!/usr/bin/ksh

or whatever your path to your Korn Shell is.

For 2)
To see which variables are exportet, use something like

env| grep <nameofyourvariable>

That you can see the value with echo is a good sign.
Afaik, with set, you only see what is in your current shell, not which has necessarily been exported.
You can test it by just using set A=1 and then use set. You will see it, but not when you use env.

Example:

root@isau02:/tmp> A=1
root@isau02:/tmp> set| grep ^A
A=1
root@isau02:/tmp> env| grep ^A
root@isau02:/tmp> export A=1
root@isau02:/tmp> set| grep ^A
A=1
root@isau02:/tmp> env| grep ^A
A=1

After exporting you can start another shell from your current session and do "env| grep <yourvariablesname>" and will see that it has been definetly exported.

thanks a lot,My 1st problem is solved :slight_smile:

but for 2nd,when I am using
# env | grep P4USER
# env | grep COMMON_USER_HOME

it is executing but not able to see the anything and when I am trying it by using

# echo $P4User

# echo $COMMON_USER_HOME

#

it means,it is not been set..

It would help if you could post the file profile.ksh here so we don't have to speculate about what could be wrong.

In addition: If you are just having variables in this script, it might be a way to just source this enviornment file, which would export all variables automatically. Sourcing means that you have a single dot in front of the script, when calling it. This could be done one the promt and also in some other script like .profile, which would be called at login automatically.

Example:

cat env_one
A=1
B=2

#then
. ./env_one

#start another shell to see if it's exported
ksh
env| grep -E "^A|^B"

No,I don't have variables in my script.I have more other operations in that.for my application I have to set the variable and after using that I am unsetting those variables.

I want it from my script,I am not able to understand why they are not being set by the script ??