Lazy Calculation result of bash functions in alias

I want to open new terminal window in current location by simple command in Ubuntu

gnome-terminal --working-directory=`pwd` & disown

Work's nice for me. But when I put alias to bashrc

alias clone="gnome-terminal --working-directory=`pwd` & disown "

pwd Calculated at start. So i get something like.

$ type clone
 clone is aliased to `gnome-terminal --working-directory=/home/user & disown '

Is it possible make pwd calculate only when i call alias. Or I need to write bash function except alias?


Just use single quotes around the alias declaration command so that the command substitution (pwd) does not take place while declaring (and will expand only when the alias is called):

alias clone='gnome-terminal --working-directory=`pwd` & disown'

Also start using command substitution syntax $() instead of older and problematic ``:

alias clone='gnome-terminal --working-directory="$(pwd)" & disown'

Also note that gnome-terminal is designed in such a manner that whenever you do

gnome-terminal

it would open a new window with the same PID as the original one. This is because its the same process by design, exiting one won't kill the other(s). So you don't need the disown and backgrounding (&), just:

alias clone='gnome-terminal --working-directory="$(pwd)"'

would do.

Moreover, as pointed out by @Digital Trauma, gnome-terminal always starts off at current working directory, so --working-directory is not needed as you are setting it as pwd. So you can just do:

alias clone='gnome-terminal'