-- Leo's gemini proxy

-- Connecting to g.codelearn.me:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

Bash. Variables inside aliases


Hey,


Recently I had to use bash alias that contains `$(pwd)` inside so I've defined it like that:


alias thename="something $(pwd) --option=value"

Of course I know a bit of bash so that's why I use double quotes!


But it turned out to be wrong. Each time when my bash/zsh was opened the alias was defined with **INTERPRETED** `$(pwd)` which is the directory where bash was opened (usualy home dir).


Actually we have to use single quotes to make sure that `$(pwd)` isn't interpreted at the moment of alias definition but it is when we call the alias.


Summary


use single quotes if you want to make sure variable/command is interpreted during the alias call.

use double quotes if you only want to interpretate variable/command on the alias definition stage (and only once).

-- Response ended

-- Page fetched on Sat May 11 20:55:16 2024