I would like to append some commands to ${HOME}/.bashrc file.
I made a script to do it.
# file name : setup_bash
bashrc_path="${HOME}/.bashrc"
comment="test"
sudo echo "${comment}" >> "${bashrc_path}"
and run it by
bash setup_bash
And it results in an error.
setup_bash: line 19: /home/user/.bashrc: Permission denied
line 19 is at (sudo echo ...).
Next I tried the following code,
sudo bash setup_bash
It results in success.
What is the difference of them? Please teach me it.