Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS X echo $(date) in .bash_profile gives stale date

In terminal, if i run echo $(date), it will give me the current date.

However, when i put the command in .bash_profile as an alias

alias dt="echo $(date)"

it will give me stale date. Namely, when i run dt, it will always give me the same date.

Any workaround? Thanks!

like image 330
sbs Avatar asked Oct 03 '22 21:10

sbs


1 Answers

You need to quote it to prevent expansion:

alias dt="echo \$(date)"
alias dt="echo \"\$(date)\""  ## (internally quoted)

Or just use a single quote:

alias dt='echo $(date)'
alias dt='echo "$(date)"'  ## (internally quoted)

And better yet use a function:

dt() { echo "$(date)"; }
like image 192
konsolebox Avatar answered Oct 18 '22 22:10

konsolebox