Shell scripting syntax

mydate ="$(date)"

what is the use of adding double code and parenthesis in the above code ..
can i write the same code as

 mydate= $date

Is this a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

If this is not a homework assignment, please explain where these questions originated and explain what you are working on? Also specify what operating system and shell you're using? (The code shown in the second question is not valid POSIX shell syntax.)

i am just learning shell scripting and came across some doubts as i check some possible interview questions and my doubts .

This line is of no use at all, because it contains a syntax error.

Actually yes, because it contains the same syntax error and will equally not work.

I hope this helps.

bakunin

/PS: only now saw that Don already mentioned it.

actually i want to put the output of the command date into the shell variable mydate

mydate ="$(date)"

I have understood that. This line is just not producing what you want and you may want to find out why.

Intead of checking interview questions you might want to consider firing up a terminal, enter your command line and then checking what is in the mydate variable. Then you can try to make it work in the way you expected it and at the end you will have learned a valuable lesson about shell scripting - instead of checking off one more question with our answers and having it forgotten in 2 minutes.

I hope this helps.

bakunin