ZSH/Shell variable assignment/usage

Two things are going wrong here.


Firstly, your first snippet is not doing what I think you think it is. Try removing the second line, the echo. It still prints the date, right? Because this:

DATE= date +'20%y-%m-%d'

Is not a variable assignment – it’s an invocation of date with an auxiliary environment variable (the general syntax is VAR_NAME=VAR_VALUE COMMAND). You mean this:

DATE=$(date +'20%y-%m-%d')

Your second snippet will still fail, but differently. Again, you’re using the invoke-with-environment syntax instead of assignment. You mean:

# note the lack of a space after the equals sign
FILE="~/path/to/_posts/$DATE-$1.markdown"

I think that should do the trick.


Disclaimer

While I know bash very well, I only started using zsh recently; there may be zshisms at work here that I’m not aware of.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)