It is currently Wed May 23, 2018 1:15 am

how to change time with .bashrc and alias

All times are UTC - 6 hours

Post new topic Reply to topic  [ 5 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.

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

Joined: Wed May 03, 2006 2:05 pm
Posts: 273
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):

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!

 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)

 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.



date() { ((! $#)) && printf '%s %s\n' 'Today is:' "$(command date)" || command date "[email protected]"; }



In order:

I invite you to follow the full BashGuide.

P.S.: Wooledge >> TLDP.

 PostPosted: Tue Oct 21, 2014 5:36 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 574
alias date='/bin/date +"Today is : %Y %m %d and time is %H:%M" '
# it's anyway a bad idea to use existing command name as an alias.

# nice for easy lookup of date formatters
man date | grep -E -e '^[[:space:]]+%'

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: No registered users and 3 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:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group