Register
It is currently Wed Sep 17, 2014 1:35 pm

how to change time with .bashrc and alias


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Sun Sep 25, 2011 6:32 am   

Joined: Sun Sep 25, 2011 6:24 am
Posts: 1
i want to set massage(Today is) when i type date command.please solve it for me.and please refer me any site for learn more about it.


Top
 Profile  
 PostPosted: Tue Sep 27, 2011 11:16 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Hello fahadul!

It sounds like an alias is exactly what you want. Take a look at the alias documentation on TLDP (the linux documentation project):
http://tldp.org/LDP/abs/html/aliases.html

As far as what commands to use, you'll likely want to use "echo" to combine your "Today is" text with the output of "date".

I hope this helps!


Top
 Profile YIM  
 PostPosted: Tue Sep 27, 2011 11:07 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Tip: don't make an alias called 'date' and use the command 'date' in it :)
(you can use the full path /bin/date)


Top
 Profile  
 PostPosted: Sat Nov 05, 2011 9:31 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Sounds like a homework...?

Anyway, does it have to be printed just when typing « date », with no arguments?
If so, you'll have to write a function called « date » too in your .bashrc file, in which you'll check whether
there are arguments, and if not, print the string « Today is:<blank> » followed by
the output of the date command. (hint: the keyword command)
If there are arguments, then simply run date(1) with the arguments provided.

----

Solution:

Code:
date() { ((! $#)) && printf '%s %s\n' 'Today is:' "$(command date)" || command date "$@"; }


----

Understanding:

In order:


I invite you to follow the full BashGuide.
----

P.S.: Wooledge >> TLDP.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP