LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   writing array into file (https://www.linuxquestions.org/questions/linux-newbie-8/writing-array-into-file-805762/)

mech123 05-03-2010 11:09 PM

writing array into file
 
How can we write arrayValues in file?
Lets say arrayName=(1 2 3 4 5)
Now if i want to write these arrayValues into file
In first line in file :1
In second line in file :2
In third line in file :3
In fourth line in file :4
In fifth line in file :5

murugesan 05-04-2010 01:32 AM

It will be nice to post the program/script name for the query posted here.

rajivdp 05-04-2010 02:30 AM

Find the script below for which you need bash shell

Quote:

#!/bin/bash
arrayName=(1 2 3 4 5)
for x in `seq 0 $(( ${#arrayName[@]} - 1 ))`; do
echo "${arrayName[$x]}" >> testing
done

grail 05-04-2010 02:39 AM

Or just:
Code:

#!/bin/bash
arrayName=(1 2 3 4 5)

for x in ${arrayName[@]}; do
    echo "$x" >> testing
done



All times are GMT -5. The time now is 04:30 PM.