LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Reading crontab into bash array (https://www.linuxquestions.org/questions/programming-9/reading-crontab-into-bash-array-447356/)

nutthick 05-22-2006 09:41 AM

Reading crontab into bash array
 
I'm trying to get the contents of my crontab into a bash array with the following code
Code:

crontab -l > /home/test/cron.tmp

declare -a crons

exec 0</home/test/cron.tmp
while read line
do
crons($line)
done

echo ${crons[@]} 1> /home/test/out.tmp

The problem I'm having, is whenever the script comes across a '*' in the cron file, it echos the contents of the current directory instead of echoing a '*'.

Any idea what I'm doing wrong?

Thanks

Disillusionist 05-22-2006 12:43 PM

Have you tried quoting the variable?

echo "${crons[@]}" 1> /home/test/out.tmp

or

echo '${crons[@]}' 1> /home/test/out.tmp

nutthick 05-22-2006 12:44 PM

Thanks for the reply, I've just solved it by using printf to write to the file instead of echo.


All times are GMT -5. The time now is 12:31 AM.