How to add alias to .bashrc via shell script?

0

I would like to append a command alias to a .bashrc file via script. However, I got confused when it comes to escaping it.
The alias is simple:

logtee() {
    tee -a "${SCENARIO_LOG_FOLDER:?'empty_log_folder'}/$1"
}

I've seen answers to similar question, but echo -e doesn't work in this case.

chester89

Posted 2016-08-03T10:30:04.780

Reputation: 149

Answers

1

You have to escape " and $ in your content:

echo -e "logtee() {
    tee -a \"\${SCENARIO_LOG_FOLDER:?'empty_log_folder'}/\$1\"
}" >> ~/.bashrc

Lasse Meyer

Posted 2016-08-03T10:30:04.780

Reputation: 238

yep, that works. thanks. can you suggest some article I can read on escaping? or man page? – chester89 – 2016-08-03T10:42:37.130

http://wiki.bash-hackers.org/syntax/quoting – Lasse Meyer – 2016-08-03T10:43:11.730