Score:3

Risks of replacing .bashrc file from one computer to another

id flag

I have 2 Asus Zenbook laptops running Ubuntu 20.04.3LTS (my current laptop and I kept my old laptop as an emergency backup system as I can't be without a laptop). I very rarely use the old one, but I run sudo ap-get update and sudo apt-get upgrade every 3-4 weeks.

When I last opened it a couple of days ago, I got an error when I opened the terminal:

bash: /home/will/.bashrc: line 100: unexpected EOF while looking for 
matching `)'
bash: /home/will/.bashrc: line 121: syntax error: unexpected end of file  

... although it seems to work fine for everything I've tried to do in the terminal.

As is so often the case, there's nothing obvious in the lines mentioned in the error that is the cause - I've had a quick look through and can't find anything I've changed anywhere else in the file that might cause it. Whilst I could probably hunt it down eventually, it's probably easier to replace the file.

My question is - as I have a second similar laptop running an identical version of Ubuntu, is there any reason not just to copy the functioning .bashrc from the newer laptop to replace the damaged one on my old laptop? I could presumably instead replace with the original version from a live USB (there are some posts on this site suggesting indirectly that that is possible), but it occurred to me that some of the aliases I created (and therefore in the .bashrc on my newer laptop) would be useful to have on the old laptop.

If this is possible, please also say if you're aware of any circumstances when it would not be a good idea. Presumably not sensible between different releases of Ubuntu? This isn't relevant to my situation, but (out of interest) I assume it wouldn't matter if the hardware is very different (eg laptop vs desktop)?

Edit: in response to the comments: it is a self contained file. The only modifications I have (knowingly) made are to add some aliases (to sync data on my encrypted partition with an external keypad encrypted drive). I’ve obviously had a look at the aliases to check I didn’t make a simple mistake but can’t find anything obvious.

mchid avatar
bo flag
It looks like there is an unmatched ( on line 100 and possibly an invisible whitespace or special character on line 121. In any case, replacing the file should be an easy fix (see my answer below).
cn flag
It's strange that this error just started happening, isn't it?
Will avatar
id flag
It is strange ... though it might have been there for a while - it's not that obvious if you're not expecting something - I am pretty sure it'll be human error and I've done something funny to the file whilst editing it.
bac0n avatar
cn flag
`diff -y -W130 ~/.bashrc /etc/skel/.bashrc | cat -n` is a good start
muru avatar
us flag
Is your `.bashrc` self-contained? What sort of modifications do you make to it? Without this information, it's not possible to give a reasonably sound answer.
Will avatar
id flag
@muru - thanks. Yes, it’s self contained. The only modifications I’ve knowingly made are to add aliases to run a synchronisation between the laptop and external drive using rsync. I’ve edited the question with this information.
muru avatar
us flag
@Will have you tried running shellcheck on it? It's also an installable program you can use if you don't want to send your bashrc to a website.
vanadium avatar
cn flag
Despite of its verbosity, your question simply is "Risks of replacing .bashrc file from one computer to another". So please stick to it. Any attempts to debug your file is out of scope of the question as you asked it.
Will avatar
id flag
@muru - thanks for that; as vanadium says my main interest was to see if you can copy the file from one system to another, but it looks useful if I face other problems so thank you!
Will avatar
id flag
@vanadium - yes, I have the -v option in my question!! You're right, I was interested in replacing the file.
Score:7
bo flag

I don't think there is any reason not to copy and replace the old .bashrc file with the new unless you have a large amount of custom configurations in the file.

The new .bashrc file will be a good, perfectly functioning replacement, assuming there are no user specific custom configurations in the new file.

Just to be safe, it's always best to make a backup of the old file.

Score:2
cn flag

The error could be fixed by inspecting your current .bashrc file. However, if you did not do extensive customizations, the safest way, rather than copying a file from somewhere else, will be to reset your current .bashrc to the system default one:

cp /etc/skel/.bashrc ~
Will avatar
id flag
Useful answer ... gave me the confidence to do the copy from one computer to another knowing I could restore to default if it went wrong.
Will avatar
id flag
thanks, have already upvoted both answers and accepted one.
Score:0
id flag

Thanks to both the answers above - just to confirm I tried it from one laptop to another and it was absolutely fine, and resolved the errors.

I didn't bother making a backup of the old file as it was corrupted anyway, and I knew (thanks to @vanadium answer) how to restore from the system default if it went wrong. For me it was quite useful to be able to do this as it preserved my aliases.

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.