* [gentoo-user] [OT] Read date input from text file problem
@ 2023-08-06 2:28 Walter Dnes
2023-08-06 3:38 ` Paul Colquhoun
0 siblings, 1 reply; 3+ messages in thread
From: Walter Dnes @ 2023-08-06 2:28 UTC (permalink / raw
To: Gentoo Users List
I have a situation where something that works as a literal but
doesn't work when reading from a text file. Here's the problem,
simplified...
I have a text file ztest.txt consisting of one line...
"August 14, 2021"
...and I have a script ztest consisting of...
#!/bin/bash
xtoday=$( date --date="August 14, 2021" +%F )
echo ${xtoday}
read < ztest.txt
echo "${REPLY}"
xtoday=$( date --date="${REPLY}" +%F )
echo ${xtoday}
Running the script produces three lines of output...
2021-08-14
"August 14, 2021"
date: invalid date ‘"August 14, 2021"’
What am I doing wrong?
--
I've seen things, you people wouldn't believe; Gopher, Netscape with
frames, the first Browser Wars. Searching for pages with AltaVista,
pop-up windows self-replicating, trying to uninstall RealPlayer. All
those moments, will be lost in time like tears in rain... time to die.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [gentoo-user] [OT] Read date input from text file problem
2023-08-06 2:28 [gentoo-user] [OT] Read date input from text file problem Walter Dnes
@ 2023-08-06 3:38 ` Paul Colquhoun
2023-08-06 13:52 ` [gentoo-user] Re: [SOLVED] " Walter Dnes
0 siblings, 1 reply; 3+ messages in thread
From: Paul Colquhoun @ 2023-08-06 3:38 UTC (permalink / raw
To: gentoo-user
On Sunday, August 6, 2023 12:28:26 P.M. AEST Walter Dnes wrote:
> I have a situation where something that works as a literal but
> doesn't work when reading from a text file. Here's the problem,
> simplified...
>
> I have a text file ztest.txt consisting of one line...
>
> "August 14, 2021"
>
> ...and I have a script ztest consisting of...
>
> #!/bin/bash
> xtoday=$( date --date="August 14, 2021" +%F )
> echo ${xtoday}
> read < ztest.txt
> echo "${REPLY}"
> xtoday=$( date --date="${REPLY}" +%F )
> echo ${xtoday}
>
> Running the script produces three lines of output...
>
> 2021-08-14
> "August 14, 2021"
> date: invalid date ‘"August 14, 2021"’
>
> What am I doing wrong?
The date in the text file shoudn't have the quotes around it.
--
Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/
Asking for technical help in newsgroups? Read this first:
http://catb.org/~esr/faqs/smart-questions.html#intro
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gentoo-user] Re: [SOLVED] [OT] Read date input from text file problem
2023-08-06 3:38 ` Paul Colquhoun
@ 2023-08-06 13:52 ` Walter Dnes
0 siblings, 0 replies; 3+ messages in thread
From: Walter Dnes @ 2023-08-06 13:52 UTC (permalink / raw
To: gentoo-user
On Sun, Aug 06, 2023 at 01:38:21PM +1000, Paul Colquhoun wrote
>
> The date in the text file shoudn't have the quotes around it.
Thank you very much. That works. The actual data file I'm working
with has quotes around the dates, so I have to insert an extra step to
strip out the quotes with sed. Using the same ztest.txt file...
#!/bin/bash
xtoday=$( date --date="August 14, 2021" +%F )
echo ${xtoday}
read < ztest.txt
ytoday=$( echo ${REPLY} | sed "s/\"//g" )
xtoday=$( date --date="${ytoday}" +%F )
echo ${xtoday}
...produces...
2021-08-14
2021-08-14
--
I've seen things, you people wouldn't believe; Gopher, Netscape with
frames, the first Browser Wars. Searching for pages with AltaVista,
pop-up windows self-replicating, trying to uninstall RealPlayer. All
those moments, will be lost in time like tears in rain... time to die.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-06 13:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-06 2:28 [gentoo-user] [OT] Read date input from text file problem Walter Dnes
2023-08-06 3:38 ` Paul Colquhoun
2023-08-06 13:52 ` [gentoo-user] Re: [SOLVED] " Walter Dnes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox