export not working in Bash shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting export not working in Bash shell
# 1  
Old 03-10-2010
export not working in Bash shell

Hi Friends,
I am presently migrating shell scripts writter in KSH to SH.I am stuck at this place and i am not able to find a work around:-
Let the script name is x.sh
Below are some of the codes in it...
Code:
export abc[0]=hello
export abc[1]=hi
export abc[2]=how

When i am trying to compile the script
Code:
line 78: export: `LOCAL_SENDER_QUEUE_NAME[0]': not a valid identifier

I did some preliminiary research and from the "man bash" found out that
"Array variables may not (yet) be exported"

I am trying to find a work around for it.

Last edited by Yogesh Sawant; 03-11-2010 at 05:54 AM.. Reason: added code tags
# 2  
Old 03-10-2010
Quote:
Originally Posted by amit.behera
I am presently migrating shell scripts writter in KSH to SH.
sh doesn't support arrays. Why not staying with ksh ?
# 3  
Old 03-10-2010
# 4  
Old 03-11-2010
Jlliagre, i am converting script from KSH shell to SH shell for some backward compartibility factors in some other servers.

Jgt, i didnot get anything from the link you have given.

My problem stands the same:-

if in SH shell we give
export abc=def----->then it works very fine without any problem.

Now here comes the problem:-

The below is an array :-
Code:
export abc[0]=hello
export abc[1]=hi
export abc[2]=how

which is creating the problem as exporting array is not supported in SH.

I just want to have alternate statements doing the same thing in SH shell.

Last edited by Yogesh Sawant; 03-11-2010 at 05:56 AM.. Reason: added code tags
# 5  
Old 03-11-2010
The link does contain some clues though. Try emulating arrays like this:
Code:
export abc_0=hello
export abc_1=hi
export abc_2=how
# Show exported variables
export
# Reference variables
for i in 0 1 2 ; do
  eval echo abc_$i: \$abc_$i
done

# 6  
Old 03-11-2010
Quote:
Originally Posted by amit.behera
Jlliagre, i am converting script from KSH shell to SH shell for some backward compartibility factors in some other servers.
Hmm, are these antiques ?
ksh and bash for that matter have been around since more than a couple of decades.
# 7  
Old 03-11-2010
Thanks very much.
The work around clicked
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Aliases NOT working inside bash shell script

i have defined a function ln_s() for customizing the ln command in script1.sh. more script1.sh echo "Starting Execution" ./script2.sh echo "End of Execution" ln_s(){ ] && return ln -s "$1" "$2" } My script1.sh executes another script2.sh which has the following entry more script2.sh... (12 Replies)
Discussion started by: mohtashims
12 Replies

2. Shell Programming and Scripting

Linux/bash Script only working if executed from shell prompt

Hi, maybe I'm asking a VERY dumb question, but would anybody out there tell me, why this f****** script won't work if executed as a cronjob, but works fine if executed from a shell prompt? #! /bin/bash set PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin date >>... (3 Replies)
Discussion started by: beislhur
3 Replies

3. Shell Programming and Scripting

Invoking a bash shell with an export var

Hello all, How can I invoke the bash shell (via command line) to execute another command by setting an exported environmental variable on the fly (as this env var would be used by the command -another script, the bash would execute). This needs to be done in one single line as the same would... (4 Replies)
Discussion started by: Praveen_218
4 Replies

4. Shell Programming and Scripting

Bash shell script not working-picking segment patterns from a file

Hi All, I have to pick particular segments from a file and I have prepared below shell script.But its not working and I am not able to find out whats the issue.could you guys pls help? Sample file: TS3*1451575*12*20151231*4*482.44 NM1*QC*1*CUTLER*BETTY DTM*472*20150808... (4 Replies)
Discussion started by: Venkata Prasad
4 Replies

5. Shell Programming and Scripting

how can I export an alias and use it in any shell that I want to switch to like bash, ksh

None of the aliases that I set are available if I switch to a different shell. How can I export aliases and make them available in any shell that I switch to like ksh or bash ? I tried these $>alias godata='cd /home/kc/app/data' $>alias -x godata='cd /home/kc/app/data' $>alias |... (2 Replies)
Discussion started by: kchinnam
2 Replies

6. Shell Programming and Scripting

Parameters passed to commands but not working in Bash shell

Hi, I am trying to do this thing useing my shell bash ( sorry for my english ) I have in a file 63 hostnames, i wanna ask to the DHCP admin, to reserv that reserves 63 IP addresses of this hosts, using their mac address. I have thinked this script: for ((i=1;i<63;i++)); do arp $(head... (10 Replies)
Discussion started by: Cypress
10 Replies

7. UNIX for Dummies Questions & Answers

Anyone know?: How the 'for'-loop could stop working in interactive bash shell?!

It is happening with my sessions already second time: a 'for'-loop for some reason stop to work as expected. That means or it is looping without exitting, or it is not loop even once. Here example of my try when it is not processing even one loop. You can see, I start new subshell and... (14 Replies)
Discussion started by: alex_5161
14 Replies

8. Shell Programming and Scripting

if loop not working in BASH shell

i have this code for a simple if loop: #!/bin/bash array="1 2 3 4 5" array2="5 6 7 8 9" if } -gt ${array} ]; then echo "${array2} is greater than ${array}!!" fi the error is ./script8: line 9: [: too many arguments ./script8: line 9: [: too many arguments ./script8: line 9: [:... (10 Replies)
Discussion started by: npatwardhan
10 Replies

9. UNIX for Dummies Questions & Answers

korn shell to bash - statement not working

Everything else seems to be working, but this isn't. Is it the "cat..." that is wrong of the condition? Thanks. cat tc_result.txt | while read LINE do if then let "files_run += 1"; echo "inside the if loop" # save current filetype case $LINE... (5 Replies)
Discussion started by: brdholman
5 Replies

10. Shell Programming and Scripting

Export Query not Working in Shell

I am exporting data using a shell program. I am getting all of the records instead of getting a subset based on my query. The export_problem.par lists all of my tables. I tried the query with the ' and without it. How do I get the export to use the query? Thanks! ... (1 Reply)
Discussion started by: GEBRAUN
1 Replies
Login or Register to Ask a Question