LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 10-15-2008, 09:37 AM   #1
fusion1275
Member
 
Registered: Jul 2007
Location: Knaphill, Surrey
Distribution: Linux Mint
Posts: 310

Rep: Reputation: 36
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
fi

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, 09:56 AM   #2
kike_coello
Member
 
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, 05:06 PM   #3
fusion1275
Member
 
Registered: Jul 2007
Location: Knaphill, Surrey
Distribution: Linux Mint
Posts: 310

Original Poster
Rep: Reputation: 36
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.

BUT

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.

Rgds
 
Old 10-15-2008, 05:19 PM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

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

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


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:19 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration