0

Currently, I have a script that adds lines into .bashrc. Here are a few of the lines. I feel this is not the most elegant way to do this. Is there a better way?

echo 'echo -e "\033[1mhtop\033[0m \033[3m(Display dynamic real-time information about running processes)\033[0m"' >> ~/.bashrc && \
echo 'echo -e "\033[1mneofetch\033[0m \033[3m(CLI tool to display information about your operating system, software and hardware)\033[0m"' >> ~/.bashrc && \
echo 'echo -e "\033[1mnethogs =\033[0m eg; sudo nethogs \033[4meno1\033[0m \033[3m(Monitor bandwidth usage per process)\033[0m"' >> ~/.bashrc
kvantour
  • 25,269
  • 4
  • 47
  • 72

2 Answers2

0
cat <<EOF >>~/.bashrc
blabla
blabla
blablablalba
EOF
Ipor Sircer
  • 3,069
  • 3
  • 10
  • 15
  • 3
    Can you provide some explanation to your answer to assist future readers? – WhatsThePoint Nov 13 '18 at 08:25
  • This is called the _heredoc format_ which tells _cat_ to read from the stdin stream until the specified _end is of stream marker is found. In our case the single word "EOF". @kennytm summarized it very nicely: https://stackoverflow.com/a/2500451/1177024 – Michael Kargl Nov 13 '18 at 12:12
  • Worked as expected. I added a back slash to `cat <<\EOF >>~/.bashrc` to avoid variable substitution as explained [here](https://stackoverflow.com/questions/22697688/how-to-cat-eof-a-file-containing-code#answer-22698106) –  Nov 13 '18 at 17:57
0

you can use brackets, to avoid copying the redirection.

{
   echo … &&
   echo … &&
   echo …
} >> ~/.bashrc

Note: the / is never needed after a &&.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52