[solved] Define env variable in .bash_profile's alias


This is in no way related to Hugo, but if anybody has the quick knowledge to help me, that’d be much appreciated.

For this project I am using a simple alias defined in my .bash_profile to compile hugo, grunt, rsync to the server etc… not the ideal setup that’s what I’m dealing with anyway.

I’m willing to add an environement variable before running hugo from that Alias, but to no avail.
I’ve shortened the command to its bare minimum for test and still not working…

alias testh='cd /Users/whatever/whatever/hugo; env HUGO_ENV="production" hugo;'

I’m sure it has to do with shell interpreting the key/value strings in a weird way, but no luck on google on that… Tried removing the double quotes… No luck either.

Of course it works like a charm when using it as is in the terminal.

Anyway, appreciate the help!

I’d just create a little bash script and add it somewhere in the PATH:

#!/usr/bin/env bash
cd /Users/whatever/whatever/hugo || exit
export HUGO_ENV="production" 

What’s that trailing `?

Just some remnant of markdown… I’ll edit the post.

That’s a little bit too advanced for me :frowning: I may have to look at bash script tutorials out there.
I was looking for the magic trick I guess :slight_smile:
I will soon move out of this alias deployment hack for some CI on this project.

does it change if you use the full path to env and hugo? like /usr/bin/env - i think alias expects full paths and does not inherit your terminals environment.

1 Like

Yes! That was it :slight_smile:
Thank you @davidsneighbour :pray: