ksh array updated by multiple scripts


 
Thread Tools Search this Thread
Top Forums Programming ksh array updated by multiple scripts
# 1  
Old 10-07-2014
ksh array updated by multiple scripts

Hello!

Is it possible to update an array created in a ksh script by a child script that was spawned by the parent?

So, if I have...
Code:
#!/bin/ksh

set -A myArray "Zero" "One" "Two"
echo "0: ${myArray[0]}"
echo "1: ${myArray[1]}"
echo "2: ${myArray[2]}"

./second_script.ksh ${myArray[*]}
echo "All: ${myArray[@]}"

exit 0

Then in the child script, add elements "Three" "Four" "Five" to the array. Then print or whatever, the array from the parent script?

If not, is there a way to do something like this?

Thanks in advance.
# 2  
Old 10-07-2014
If you create a new shell, variables cannot travel from it to the old shell.

One solution would be to source the script instead of executing it, which would run it in the same shell:

Code:
. ./scriptname

The use of 'exit' is one potential pitfall, which would cause it to quit completely instead of returning, if you use exit you must use return instead in the sourced script.

Another solution would be to have the script print the values, for you to read into the old shell.
# 3  
Old 10-08-2014
Thanks. I'm just going to use a temp file. that would be the most straight forward.
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling multiple scripts from another scripts

Dear all, I am working on script which call other shell scripts in a loop but problem is from second script am not able to come out. Here is the snippet:- #!/bin/bash HSFILE=/root/Test/Components.txt LOGFile=/opt/domain/AdminDomain/application/logs... (3 Replies)
Discussion started by: sharsour
3 Replies

2. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

3. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies
Login or Register to Ask a Question