variables and functions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting variables and functions
# 1  
Old 08-08-2012
variables and functions

can somebody telll me what my values are not being displayed in the function func1()

Code:
 
{oracle@im4s012nz1_DUMMY}$ cat x1.ksh
#!/bin/ksh
getpwd()
(
set -x
   . /home/oracle/dba/bin/CyberArk/CyberArk_GetPass.ksh
   ORA_USER=$DB_UID
   ORA_PWD=$DB_PWD
   echo "Here I am 1 |DB_UID=$DB_UID|"
   echo "Here I am 1 |DB_PWD=$DB_PWD|"
   echo "Here I am 1 |ORA_USER=$ORA_USER|"
   echo "Here I am 1 |ORA_PWD=$ORA_PWD|"
)
func1()
{
   set -x
   getpwd
   echo "Here I am 2 |DB_UID=$DB_UID|"
   echo "Here I am 2 |DB_PWD=$DB_PWD|"
   echo "Here I am 2 |ORA_USER=$ORA_USER|"
   echo "Here I am 2 |ORA_PWD=$ORA_PWD|"
}
func1
 
 
when I run it
 
+ getpwd
+ . /home/oracle/dba/bin/CyberArk/CyberArk_GetPass.ksh
+ safe_name=2-AAQ-BA0-Oracle-A-A-000
+ psswordobj=Oracle_us_dba_maint_dev-ORADBAD
+ app_id=Oracle-A-1.0
+ instance_name=ORADBAD
+ DB_SERVER=ORADBAD
+ + /opt/CARKaim/sdk/clipasswordsdk getpassword -p AppDescs.AppID=Oracle-A-1.0 -p Query=safe=2-AAQ-BA0-Oracle-A-A-000;Folder=Root;Object=Oracle_us_dba_maint_dev-ORADBAD -o PassProps.UserName
UID=dba_maint
+ + /opt/CARKaim/sdk/clipasswordsdk getpassword -p AppDescs.AppID=Oracle-A-1.0 -p Query=safe=2-AAQ-BA0-Oracle-A-A-000;Folder=Root;Object=Oracle_us_dba_maint_dev-ORADBAD -o Password
PWD=f0ur3y3s
+ export DB_UID=dba_maint
+ export DB_PWD=f0ur3y3s
+ ORA_USER=dba_maint
+ ORA_PWD=f0ur3y3s
+ echo Here I am 1 |DB_UID=dba_maint|
Here I am 1 |DB_UID=dba_maint|
+ echo Here I am 1 |DB_PWD=f0ur3y3s|
Here I am 1 |DB_PWD=f0ur3y3s|
+ echo Here I am 1 |ORA_USER=dba_maint|
Here I am 1 |ORA_USER=dba_maint|
+ echo Here I am 1 |ORA_PWD=f0ur3y3s|
Here I am 1 |ORA_PWD=f0ur3y3s|
+ echo Here I am 2 |DB_UID=|
Here I am 2 |DB_UID=|
+ echo Here I am 2 |DB_PWD=|
Here I am 2 |DB_PWD=|
+ echo Here I am 2 |ORA_USER=|
Here I am 2 |ORA_USER=|
+ echo Here I am 2 |ORA_PWD=|
Here I am 2 |ORA_PWD=|

# 2  
Old 08-08-2012
What's your system?
# 3  
Old 08-08-2012
sun solaris 2.10.. this also needs to work on Linux but I have not got to that yet.
# 4  
Old 08-08-2012
You aren't doing anything to print the variables in func1(). The command:
Code:
set -x

turns shell tracing on. If you want to list the environment variables at that point instead of turning on tracing, change that line to:
Code:
set

# 5  
Old 08-08-2012
not sure what you mean as I am printing the values in func1

Code:
 
echo "Here I am 2 |DB_UID=$DB_UID|"
   echo "Here I am 2 |DB_PWD=$DB_PWD|"
   echo "Here I am 2 |ORA_USER=$ORA_USER|"
   echo "Here I am 2 |ORA_PWD=$ORA_PWD|"

# 6  
Old 08-08-2012
Note how the body of getpwd is surrounded by parens while the body of func1 is surrounded by braces? getpwd is running in a subshell. The environment changes do not propagate upwards from child to parent.

Regards,
Alister

Last edited by alister; 08-08-2012 at 05:38 PM.. Reason: typo
This User Gave Thanks to alister For This Post:
# 7  
Old 08-08-2012
alist bulleyes.. thanks. did not even notice that
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh While Loop - passing variables to functions

I'm reading a text file using a while loop but when I call a function from within this loop it exits that same iteration … even though there are many more lines in the file to be read. I thought it was something to do with the IFS setting but it appears that a function call (when run... (3 Replies)
Discussion started by: user052009
3 Replies

2. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

3. Shell Programming and Scripting

awk - Why can't value of awk variables be passed to external functions ?

I wrote a very simple script to understand how to call user-defined functions from within awk after reading this post. function my_func_local { echo "In func $1" } export -f my_func_local echo $1 | awk -F"/" '{for (k=1;k<=NF;k++) { if ($k == "a" ) { system("my_local_func $k") } else{... (19 Replies)
Discussion started by: sreyan32
19 Replies

4. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

5. Shell Programming and Scripting

functions and variables in bash

I have a bash script with some functions as below and am wondering if I can use the variables declared in setup in the other functions and in the rest of the bash script. setup(){ none=0; low=1; medium=2; high=3; debug=4 var1="red" var2="fred" } create_basemap() { ... (7 Replies)
Discussion started by: kristinu
7 Replies

6. Shell Programming and Scripting

[bash] reassigning referenced variables in functions

Hello all, Problem. ---------- I'm trying to reassign a referenced variable passed to a 'local' variable in a function but the local variable refuses to be assigned the content of the referenced variable. Any ideas would be appreciated. Objective. ----------- Eliminate all $VAR... (1 Reply)
Discussion started by: ASGR
1 Replies

7. Programming

Trouble with Date Variables and Functions in PL/SQL

Hi, In the course of my script i have to compare SYSDATE with the 15th of the current month: if it is greater than i should set a variable date to 15th of the next month if less than i should set it to the 15th of the current month. In other words the question is how to set a date variable... (2 Replies)
Discussion started by: fmina
2 Replies

8. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

9. Shell Programming and Scripting

awk - arithemetic functions with external variables

I'm trying to get awk to do arithmetic functions with external variables and I'm getting an error that I cannot figure out how to fix. Insight would be appreciated money=$1 rate1=$(awk -F"\t " '/'$converting'/{print $3}' convert.table) rate2=$(awk -F"\t"... (2 Replies)
Discussion started by: DKNUCKLES
2 Replies

10. Shell Programming and Scripting

Variables and functions

I have a script that ultimately will FTP data to certain directories based on a character in the filename. I am creating a function within my script to handle the FTP call. Are the variables that are setup in the original script accessible to the function? If not, is there a way to allow them to... (4 Replies)
Discussion started by: dfb500
4 Replies
Login or Register to Ask a Question