(ksh) problem with scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting (ksh) problem with scripting
# 1  
Old 12-14-2010
Data (ksh) problem with scripting

Hello,

I have following problem...
I have two shell-scripts. The first one is only a script to add Arrays (working very good). In the second script I want to read the Arrays (also working good). I don't know how to explain it...

script:

Code:
#!/usr/bin/ksh           
. test.sh                
for i in ${array_zahl[*]}
do                       
land$i=${array_land[i]}  
done                     
land6=LUX                
echo $land6

output:

Code:
/home/gold/Release-Wechsel/Skripte_RW/test3.sh[5]: land1=DE:  not found
/home/gold/Release-Wechsel/Skripte_RW/test3.sh[5]: land2=FR:  not found
/home/gold/Release-Wechsel/Skripte_RW/test3.sh[5]: land3=NL:  not found
/home/gold/Release-Wechsel/Skripte_RW/test3.sh[5]: land4=IT:  not found
/home/gold/Release-Wechsel/Skripte_RW/test3.sh[5]: land5=GB:  not found
LUX

Why the script want to execute "land1=DE", he only should set the vars land1 to land5...

Can someone help me?

Thanks and Kind Regards
Mon5tar

Last edited by radoulov; 12-14-2010 at 12:49 PM.. Reason: Code tags, please!
# 2  
Old 12-14-2010
I believe I'd rather edit my post ...

I believe you need:

Code:
land[i]=${array_land[i]}


Last edited by radoulov; 12-14-2010 at 01:07 PM..
# 3  
Old 12-14-2010
Please post the code of both of your scripts
# 4  
Old 12-14-2010
You are missing an eval statement:
Code:
eval land$i=${array_land[i]}

# 5  
Old 12-14-2010
The eval is to make an extra pass, as you need one pass to construct the variable name and another to use it. eval is a bit like this, but in the same ksh (note the change from double to single quotes to control what gets expanded the first time -- even eval needs that, ksh is not psychic about which $ are first pass):
Code:
echo "land$i"'=${array_land[i]}' | ksh



Without eval, you need to:
  • construct a script using the variables and send it to another ksh to execute, or
  • write it to a file and source (. file_path) it,
  • or somthing like this works on Solaris and other UNIX with /dev?/fd/# file descriptors, expanding in a subshell and sourcing a pipe from that subshell:
Code:
. <( echo "land$i"'=${array_land[i] )


Last edited by DGPickett; 12-14-2010 at 01:35 PM..
# 6  
Old 12-14-2010
The OP seems to be using a shell that supports arrays, so, in my opinion, no external programs are needed.
# 7  
Old 12-14-2010
eval is a built in ksh function to allow an extra pass of evaluation, not an external program. The problem is that the name of a variable has to be constructed from a variable. An associative array could be used. Is that what you meant? Array, barefoot, is just a pile of like sized items you can index by number. Associative arrays are not arrays at all, but string maps. The name is an unfortunate side effect of overloading the array operator [] in the map call.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

KSH scripting

Hi Guys, I am trying to learn to script. first I have 2 server, A and B. A with IP 192.168.82.22. B with IP 192.168.82.44. Both with login user admin and password admin. server A will generate a file every day with name gg.log under /app/gg/20171002.log. I wish to write a script to copy the... (7 Replies)
Discussion started by: leecopper
7 Replies

2. Shell Programming and Scripting

ksh scripting

Hi All, Can you please let me know what I missed in the below function? Whenever I try to execute the script i am getting syntax error at line 101 : `fi' unexpected Function is function DELNWE5O { export ORACLE_HOME=/ora00/app/oracle/product/11.2.0/grid_1 export... (9 Replies)
Discussion started by: pvmanikandan
9 Replies

3. Shell Programming and Scripting

Help with ksh scripting in AIX

I am looking for a script which does the following Script will run daily. 1.It will get snapshot off all filesystems including nfs mounts, automounts and clearcase mounts. 2.Then it will compare new snapshot with the snapshot created in the previous run. 3.If filesystem exists in... (20 Replies)
Discussion started by: saidiya
20 Replies

4. Shell Programming and Scripting

Problem with Ksh scripting

Hi, Below is the code for my script #!/bin/ksh for file in "file1.txt" "file2.txt" "file3.txt" "file4.txt" do L="$(tail -1 $file)" NUM=${L%%|*} DAT=${L##*|} echo $NUM echo $DAT done Now here,suppose for file1.txt L will have data like 56|06-07-2010 So, it should be (7 Replies)
Discussion started by: fidelis
7 Replies

5. Shell Programming and Scripting

ksh scripting help needed.

I am trying to create a script to manipulate numerous file and at first I thought it would be a simple task but at this point i am ready to break my computer! I am new to unix scripting so hopefully someone out there thinks this is super easy and can help me out! A sample of the problem file is... (2 Replies)
Discussion started by: theqcup
2 Replies

6. Shell Programming and Scripting

ksh scripting help

I have the file as below server1 no dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server2 no dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server3 yes dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server4 ... (1 Reply)
Discussion started by: praveenbvarrier
1 Replies

7. Shell Programming and Scripting

Need help with KSH scripting

Hi I need to insert a page break into a file based on matching a phrase in the file. :confused: I am doing this with a ksh script on a Unix box. Any help would be greatly appreciated. Thanks (5 Replies)
Discussion started by: scrappycc
5 Replies

8. Shell Programming and Scripting

scripting problem ( KSh )

Hi all, I want to find out last word in each line ... suppose my file contains following lines ... this is unix forum here we share knowledge it is very interactive Now i need the output as :- ( the last word od each line ) forum knowledge interactive ... (2 Replies)
Discussion started by: dhananjayk
2 Replies

9. Shell Programming and Scripting

ksh scripting sprintf

is there any sprintf function in korn shell scripting, or anything similar to sprintf? (2 Replies)
Discussion started by: gfhgfnhhn
2 Replies

10. Shell Programming and Scripting

KSH Scripting

Will a shell script written in shell for HP/UX run on Solaris? (1 Reply)
Discussion started by: dstaller
1 Replies
Login or Register to Ask a Question