Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
I tried a lot of ways to pass values to some variable i made up and it works partially, i can successfully do
and to get the output '12:55', but i can't pass an output of a command 'hwclock' to the variable.. i tried 'TIME=$hwclock', 'TIME=hwclock' 'hwclock > TIME'
'$hwclock > TIME' but those wont work as i need them to.
How can i accomplish this?
Last edited by Infernal211283; 01-11-2006 at 03:07 AM.
Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed as follows:
Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).
When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by `$', ``', or `\'. The first backquote not preceded by a backslash terminates the command substitution. When using the $(command) form, all characters between the parentheses make up the command; none are treated specially.
Command substitutions may be nested. To nest when using the backquoted form, escape the inner backquotes with backslashes.
If the substitution appears within double quotes, word splitting and filename expansion are not performed on the results.
When using the $(command) form, all characters between the parentheses make up the command; none are treated
executing 'TIME=$(hwclock)' worked partially, i mean, the output of the command is usually 'Wed 11 Jan 2006 11:17:44 AM IST -0.928094 seconds' but the value $TIME stored is only 'Wed' - the [space] between 'Wed' and '11' broke the string that was supposed to be in the variable which shouldn't happen according to the above, should it?
being slow i can now say that i figured out that the error is because the file cannot be created with ':', so i turned to alternative command 'date' using it's formats (%y.%m.%d), now it all works, sorry for odd questions.
Just to enrich your learning about shell.
In general, the long format for date isn't useful for scripts and so. May be you prefer a more compact form of time. Something like this:
miguel@gold:~> date +%Y%m%d-%H%M%S
yep, just what i thought after i saw how files look if they're named after 'hwclock', i'm already trying to make a script using all this neat knowledge, hopefully i'll manage to create something intelligent.