
Every once in a while, I get on this thing about how cool (and powerful) the shell is. With a little knowledge, you can do all sorts of great things. For instance, starting up the editor of your choice to open up a work file with the day's date automatically generated. This is actually the sort of thing I do all the time. For instance, today's journal would be in a directory called /home/marcel/Daily_Journal/Saturday_Jan_17_2004. Let's step back. Open up a shell prompt and type the command "date". The result will look something like this. $ date "Nothing special there", you say. Well, what if you wanted to know the date 12 days ago. Use the "-d" modifier. $ date -d "12 days ago" It gets more interesting, doesn't it? You can also modify the output of the date command with the plus sign modifier. For instance. $ date +%A -d "12 days ago" The "%A" tells the date command to print out the long for of the day (ie: Monday instead of Mon). Check the man pages and you will see a whole lot of these modifiers. If I wanted to have the day in long form, the month in 3 letter short form, followed by the day and the year in 4 digit form, I would use the following command. $ date +"%A %b %d %G" I put quotes around the modifiers because I wanted spaces in between each one. Had I wanted underscores, it would not have been necessary. So far so good. Let's say that I wanted a command to call my favorite editor (whatever it might be) to open a daily journal in the form of Saturday_Jan_17_2004, I could put the whole thing in a script file like this. #!/bin/bash Notice the back quotes around the date command -- very important. I used the kwrite command here, but you could use vi, pico, nedit, or whatever editor you feel comfortable with. When I wrote this script, I called it "think" and saved it in /usr/local/bin. Then, I made the file executable with "chmod +x /usr/local/bin/think". All I have to do now is call the command "think" and it magically opens a pre-named daily journal text file. |
|||











think:
Keep up the good work & i watch CALL FOR HELP as many time as i can & that is were i saw you the first time.
well Marcel i just read your article on the daily journal.
I am new to linux and i like it very much so far. I use suse 10.
The script you wrote is fine but how did you know that you had to put it in /usr/local/bin(think in the perspective of a newbie) How are we to know were to install this scripts.Wy din't you put it in /home/marcel/think instead.Would it have work anyway or not.If so wy or wy not.I think that is the stuff a newbie need to know also to make him understand the working of linux commands.This is the stuff i am learning at present and loving it like crazy.(commands).
Than you say you call the "command"? think fine what "command"? are you talking about the "run command"? or do you have to open a "konsole"? to do it.(again think newbie) Ok some info is more logical than others i will admitt but.
You write: date+"%A%b%d%G" fine You say put double quotes ok.
But went you write the script you say put back quotes --very important
wy.You used double quote before now back quotes wy info i need info.
Ok Marcel i am teasing you a bit here but i whant to learn, I am tired of searching the net for hours on end for info that or I think should be supplied especially on a site like yours.
Thanks
I tried your script: I hate to say this but it dosent work.
when i do it it come back saying that the file or directory doesnot exist, so i created a dir: & a file but to no avail. Followed your script to de letter exept for the marcel i wrote my name.
Dont get upset,or mad,or hit the com, ask for help:
Post new comment