Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-22-2006, 09:41 AM   #1
Registered: Jun 2004
Distribution: Slack
Posts: 214

Rep: Reputation: 30
Reading crontab into bash array

I'm trying to get the contents of my crontab into a bash array with the following code
crontab -l > /home/test/cron.tmp

declare -a crons

exec 0</home/test/cron.tmp
while read line

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?

Old 05-22-2006, 12:43 PM   #2
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 97
Have you tried quoting the variable?

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


echo '${crons[@]}' 1> /home/test/out.tmp
Old 05-22-2006, 12:44 PM   #3
Registered: Jun 2004
Distribution: Slack
Posts: 214

Original Poster
Rep: Reputation: 30
Thanks for the reply, I've just solved it by using printf to write to the file instead of echo.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Help in BASH! ?*%$ johnnybhoy67 Linux - Software 2 02-22-2006 10:39 AM
BASH :Reading the crontab, and editing it semaja2 Programming 4 02-05-2006 06:43 AM
Reading from a txt file into a two dimension array in C kponenation Programming 3 11-26-2005 07:04 PM
Using crontab in a bash script nro Linux - Newbie 3 08-26-2005 08:04 PM
bash script for database searching using crontab saurya_s Linux - Software 5 01-22-2004 08:53 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:48 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration