LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-22-2006, 09:41 AM   #1
nutthick
Member
 
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
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
 
Old 05-22-2006, 12:43 PM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

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

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

or

echo '${crons[@]}' 1> /home/test/out.tmp
 
Old 05-22-2006, 12:44 PM   #3
nutthick
Member
 
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.
 
  


Reply


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


All times are GMT -5. The time now is 11:36 AM.

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