0

Here's the problem I have with my bash script:

    date1=(`date -d @$startdate`)
    date2=(`date -d @$enddate`)

    touch --date="$date1" /tmp/newerthan
    touch --date="$date2" /tmp/olderthan

Since the words returned by the date -d command contain spaces, the only thing that gets processed by the touch --date="$var" command is the first word (which is "Mon", "Tue", "Wed"... etc), so it doesn't work properly.

How can I work around this problem and be able to get the subsequent lines to process the entire string?

1 Answer 1

2

You've used an array assignment in:

date1=(`date -d @$startdate`)

Either use plain backquotes (definitely not the preferred technique, though):

date1=`date -d @$startdate`

Or (much better) use $(...):

date1=$(date -d @$startdate)

Or, at a pinch (there'd have to be a good reason), use this to copy the whole array into the argument to touch:

touch --date="${date1[*]}" /tmp/newerthan

You might want to consider double quotes around @$startdate, too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.