1

Pretty darn simple I would have expected. I have a large .bashrc file I made years ago where everything is spelled out for values on my alias's.

I want to reduce the size of the file and make use of a variable to reference to avoid having to change the values throughout the entire file.

I've been at this for hours this morning and cannot figure out how to get the file to work with ${} references.

Example:

alias MYID='elijah'
alias DEVHOME='/opt/data/users'
alias MYHOME='${DEVHOME}/${MYID}'

I have tried the above with single quotes, double quotes with { and without the { but cannot get anything to populate into MYHOME.

Please show me how to set MYHOME so when I echo it, it states /opt/data/users/elijah.

4

If you want variables, you shouldn’t use alias:

MYID='elijah'
DEVHOME='/opt/data/users'
MYHOME="${DEVHOME}/${MYID}"

with double quotes instead of single quotes so that the variables are expanded.

Once these are set, you can see their values using echo or any similar command:

echo "$MYHOME"

If you want their values to be available to other programs started from your shell, you need to export them too:

export MYHOME

Aliases are used to create alternate names for commands, not to store values.

  • but if you want to reference the value of MYHOME from the terminal don't I need it to be an alias? – Elijah Jul 11 at 13:54
  • 1
    @Elijah Aliases are for creating short new names for commands. If you want something that holds a string value, you want a variable, as is shown in this answer. – Kusalananda Jul 11 at 13:56
  • @Kusalananda Thank you very much. I never knew the difference for the usage. alias for setting a command reference and export for a text value. All of the stuff in my file has been aliases for commands I use shortcuts for. – Elijah Jul 11 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.