8

I think I had a typo when I add a path to ~/.bashrc and after I source it, I cannot use bash commands anymore.

Now I want to restore a normal ~/.bashrc, however most of the discussion I found (e.g. How to fix a .bashrc that's been edited wrongly?) needs to use bash commands e.g. cp

clam@cuerei:~# cp /etc/skel/.bashrc ~
cp: /home/cltam/script/lib/libc.so.6: version `GLIBC_2.17' not found (required by cp)

May I know how could I restore ~/.bashrc without using bash commands?

Thank you.

4 Answers 4

25

cp is not a bash command – it's an external program. This is why it fails; actual bash commands would be unaffected by library or path changes. So you want the opposite, i.e. using only bash commands.

You could delete the file's contents completely, using:

true > ~/.bashrc

Or overwrite with some other contents:

echo "" > ~/.bashrc

Or you could try to temporarily undo the bad changes within the live shell:

unset LD_LIBRARY_PATH LD_PRELOAD LD_AUDIT
export PATH=/bin:/usr/bin
cp /etc/skel/.bashrc ~

Or you could copy the file's contents, line by line, using just shell built-ins:

while IFS="" read -r line; do
    echo "$line";
done < /etc/skel/.bashrc > ~/.bashrc
8
  • 2
    Surely I'm not the only one who keeps staticly linked copies of critical binaries lying around.
    – Joshua
    Aug 21, 2020 at 18:08
  • 2
    Or a live USB to boot from
    – shay
    Aug 21, 2020 at 19:33
  • 4
    in a locked low-humidity temperature-controlled vault accessible only when two keys are turned simultaneously in locks that are eight feet apart .... whups, sorry. Aug 21, 2020 at 21:30
  • 4
    Or more simply, just unset LD_LIBRARY_PATH and use vim or whatever to fix the typo in your existing .bashrc, then re-source it. No need to wipe it out. Aug 22, 2020 at 0:35
  • @PeterCordes Or even LD_LIBRARY_PATH= vim ~/.bashrc. Aug 22, 2020 at 6:21
1

Are you currently logged into the system? If so, you can switch to another shell, then edit the file

> chsh
> vi ~/.bashrc
1
  • 1
    If cp won't run, what makes you think chsh will run?
    – Barmar
    Aug 22, 2020 at 23:04
1

You broke your library path which is used for dynamically linked programs. Those do not contain all the code needed to execute the program, but load some from shared libraries at start up time.

Some programs are compiled to avoid this issue (for instance for programs running as root or needed very early in the boot process). They are traditionally placed in /sbin and /usr/sbin. What exactly is there depends on what is installed.

On my Mac it does not appear that there is an editor available, but your system might have.

0

I have followed @Peter Cordes suggestion to undo my edit by: unset LD_LIBRARY_PATH.

Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.