Restoring ~/.bashrc without using bash commands

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

Tags:

Linux

Bashrc