Restoring ~/.bashrc without using bash commands

Solution 1:

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

Solution 2:

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

> chsh
> vi ~/.bashrc