Support LQ: Use code LQ3 and save $3 on Domain Registration
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 10-15-2008, 10:37 AM   #1
Registered: Jul 2007
Location: Portsmouth, Hants
Distribution: Mint 13
Posts: 265

Rep: Reputation: 35
Driving me crazy!!!

Heres my little problem...

export TODAY_DATE=`date +%Y%m%d`

echo "Enter the name of todays file: \c"
read filename
if [ ! -r "$filename" ];then
echo "Bad file name, Exiting!"
exit 1

The user inputs the following: /home/dir/file_${TODAY_DATE}.log

How can I get the date variable to hold in the user input and be read within the script???

Thanks for any help
Old 10-15-2008, 10:56 AM   #2
Registered: Jul 2005
Location: maryland
Distribution: Ubuntu 9.04
Posts: 88

Rep: Reputation: 17
more info

dude, you need to explain exactly what you want man, you want the user to input file_DATE.log? do you want to process only files that have the current date? are the files being read all beginning with "file_" and ending with ".log"? etc, etc.
Old 10-15-2008, 06:06 PM   #3
Registered: Jul 2007
Location: Portsmouth, Hants
Distribution: Mint 13
Posts: 265

Original Poster
Rep: Reputation: 35
ok so basically when I run the script it will ask me a question. I enter in a file name which has a variable of ${TODAY_DATE}. It reads that file and then does the test if its a readable file, if so then blah blah blah and if not exit with a 1.


When this is executed it does not capture the date string in the "read" user input section it only reads ${TODAY_DATE} not `date +%Y%m%d`

How can I get this to work?

the correct "if" statement using "sh -x" to debug it should go something like:

if [ ! -r /home/dir/file_20081015.log ]

but it looks like:

if [ ! -r ${TODAY_DATE} ]

The variable isnt being read only the word is captured. I hope you can understand. Its tricky to describe.

Old 10-15-2008, 06:19 PM   #4
Senior Member
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 137Reputation: 137
filename=$(eval echo $filename)
if [ ! -r "$filename" ];then

Last edited by keefaz; 10-15-2008 at 06:24 PM.


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
[ ] @ are driving me crazy FireInTheDark Linux - Software 1 11-28-2004 10:42 AM
Help this is driving me crazy!!!!!! Wolfy Linux - Hardware 1 07-07-2004 02:32 AM
Hotwayd is driving me crazy!!! Teckno Linux - Software 2 05-30-2004 02:51 PM
acidrip is driving me crazy Pwcca Linux - Software 7 01-31-2004 09:30 PM
rhythmbox driving me crazy... Camasii Linux - Software 4 01-22-2004 10:08 AM

All times are GMT -5. The time now is 02:07 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