Score:0

Trying to add a line to my bashrc but it's not working

tv flag

I am trying to add a line after I find some text to my .bashrc but I don't have my syntax correct.

Can someone help me.

I want to add the line "alias cls='clear' after the egrep line in the .bashrc file.

Here is what I have so far.

sed ':\egrep:a alias cls='clear' .bashrc

Thanks RC

ng flag
I cn't tell exactly what you're doing from your example, so I'll offer [this article](https://fabianlee.org/2018/10/28/linux-using-sed-to-insert-lines-before-or-after-a-match/).
Artur Meinild avatar
vn flag
Is there a specific reason you need to add stuff to your `.bashrc` with `sed`?
Score:3
hr flag

I can spot two issues:

  1. if you want to use : as a regex delimiter in the address expression, you need to escape the : itself not the following e character

  2. you have an unbalanced single quote

So either

sed "\:egrep:a alias cls='clear'" .bashrc

or simply

sed '\:egrep:a alias cls=clear' .bashrc

since you don't really need to quote clear here (if you ever do need to embed a single quote in a single-quoted expression, close the quote and then reopen it i.e. '\'').

To apply the changes to the file in-place, add the -i command line option.

fixit7 avatar
kp flag
Why not add it to .bash_aliases? @r-c-man
r-c-man avatar
tv flag
Thank you. I actually didn't know about .bash_aliases. I do now :) I'm looking up Bash Startup files and it doesn't show that. It shows .bash_profile, .bash_login and .profile I guess it's different depending on where you look.
hr flag
@r-c-man the `~/.bash_aliases` file isn't mentioned in the bash manual's section on shell invocation because it's not an intrinsic startup file; it's just sourced by the default Debian/Ubuntu `~/.bashrc` if it exists
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.