ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Notice the '+FORMAT' there? See the lower part of the man page for formatting strings and combine them into the command to be able to append the date/time in the format you want/need (the default format given by plain 'date' might not be what you want).
That method, redirecting the output of a command to a file using '>>', is fairly common and works in DOS too, exactly the same way (except that there might not be 'date' command available). Two greater than -chars ('>>') means 'append' while one ('>') alone clears the file contents before writing the new content, so be aware:
date >> file.log #existing content remains, date is added to the end
date > file.log #existing content vanishes, now file only contains date's output
For more information about what you can do with your shell ('tricks' if you like), see your shell's man page, for example
EDIT: of course that means the shell you use to run your script; you should define it in the first line of the script file, for example
Single quotes won't work, since they mean that the contents of the quotes are a literal string, and no expansion of the $( ... ) will be done.
You are using a strange shell which does not expand $( ... ). What is /sbin/sh? If you do not use bash, you should explicitly state what you are using in posts to LQ - most people here will assume you are using bash unless you tell them otherwise (me included).
are different notations to achieve more or less the same thing in bash and many other borne shell derivatives (including zsh, ksh and dash). i.e. "execute a command, and put the output of the command (from standard output) here".
In all these shells you can also use the `backtick` notation. I prefer not to instruct people using backticks for two reasons:
They are extremely easy to confuse with single quotes, and often lead to a lot of back and forth because the font which is used to display the message either doesn't discriminate at all between the two characters, or the reader does not pay close enough attention.
Backtick execution is not nestable. Using $(...), you can have an "inner" execution, which is done first. This is not such a huge reason... it is not a commonly used feature, although I will say that I have used it in the past. Sure enough it's possible to do the same thing in two stages with backticks, but sometimes it's nice to be able to nest these things.