-4
echo -en "date: "
read sdate
mdate="date -d '${sdate} 00:00:00' +%s "
udate(){ 
$mdate 
}
udate

output

root@Xanarchy:/cnc# bash date
date: 01-01-2000
date: extra operand ‘+%s’
Try 'date --help' for more information.
Andy Dalton
  • 13,654
  • 1
  • 25
  • 45
  • 2
    What you're doing there falls squarely in ["How can we run a command stored in a variable?"](https://unix.stackexchange.com/q/444946/170373). Here, you'd be best off just spelling the command out in the function instead of using a variable. But you're not reading the output of the command there, at all. You'd need `output=$(date ...)` or so for that. – ilkkachu Nov 24 '21 at 18:16
  • 6
    Please [edit] your post and i) ask a question; ii) explain what you are trying to do and how it fails and iii) give a descriptive title: remember that the title is all people see when looking at the home page, so if you don't explain what the question is in the title, people will ignore it. – terdon Nov 24 '21 at 18:17
  • 4
    Does this answer your question? [How can we run a command stored in a variable?](https://unix.stackexchange.com/questions/444946/how-can-we-run-a-command-stored-in-a-variable) – Greenonline Nov 25 '21 at 04:06

1 Answers1

0
echo -en "date: "
read sdate
mdate=(date -d "${sdate} 00:00:00" +%s)
udate(){
"${mdate[@]}"
}
udate

Using a string makes this unnecessarily complicated. Using an array is much simpler.

01-01-2000 is illegal input for date. You need 2000-01-01.

Hauke Laging
  • 88,146
  • 18
  • 125
  • 174