'A shell script question about Apostrophe and Quotation Mark

I writing a script that adds alias in .bashrc automatically.

I have to write alias A='source /MY_HOME_DIR/a.sh' in the .bashrc.

So my script was echo "alias A=/'source ${HOME}/a.sh\'" >> ~/.bashrc but It's not working.

Any idea? thank you in advance.



Solution 1:[1]

echo "alias A='source ${HOME}/a.sh'"

is working well.

It's interesting. I though ${HOME} won't work between ''.

Solution 2:[2]

It is because you miss $ sign before {HOME}.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 S-K
Solution 2 Faizan Younus