Domanda

I can't imagine I'm the only Mac user that has this need. Basically, I have custom aliases that include outputting dates. However, I have to re-source my .basrc if I want the dates to be right when I use my computer the next day.

One use for this is posting work hours via command line.

Example:

"post -d `date -v-1d "+%Y-%m-%d"`"

Today, that alias will correctly resolve to:

"post -d 2014-04-02"

However, tomorrow it will STILL show 2014-04-02 unless I re-source my .bashrc.

The real question I have is: how do I auto source my .bashrc on a monthly schedule?

I actually only need to re-source it once a month (I'm doing monthly posts). I was going to set it up as a cron job, but I thought, what if my computer isn't on during the 1st of the month? What if it's a holiday. I need something that will run this once the computer comes back online.

So, I looked into anacron instead. Appears that's not a mac utility nor is it home brew installable. Looks my solution is actually going to be launchd. But I'm not quite sure if that's the right track.

Anyone know if launchd is what I need or how that would be set up? I can only seem to find information about setting environment variables. Thanks!

È stato utile?

Soluzione

stackoverflow's markup is confusing. To solve your issue compare these two aliases:

alias p='echo `date +%T`'
alias pp="echo `date +%T`"

Just change double quotes with single ones.

Altri suggerimenti

It makes a difference whether you use single or double quotes. With double quotes, the shell will execute it in line. With single quotes the shell passes it on literally and it executes when you run the alias:

$ alias p='echo `date`'
$ p
Thu Apr 3 12:56:02 EDT 2014
$ p
Thu Apr 3 12:56:03 EDT 2014
$ p
Thu Apr 3 12:56:04 EDT 2014

$ alias p="echo `date`"
$ p
Thu Apr 3 12:57:14 EDT 2014
$ p
Thu Apr 3 12:57:14 EDT 2014
$ p
Thu Apr 3 12:57:14 EDT 2014

Another illustration of double versus single quote behavior, for the same reason, is evaluation of shell variables:

$ x=1
$ echo '$x'
$x
$ echo "$x"
1
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top