3

I was trying to add sql to my zsh file and I ran this code I found online:

echo 'export PATH=${PATH}:/usr/local/mysql/bin/' >.zshrc

When I opened .zshrc, this was the only line in the file and everything I had before was deleted.

Can someone please help me in understanding if I can revert back to what I had before I made this change? Or is everything just lost now? And what about this line of code did this?

FYI, I'm using Mac. Also, things like commands like "brew" and "npm" are still working, despite my .zshrc being empty. I don't know if that's telling or helpful in any way. ("sql" still doesn't work)

Brandon H
  • 31
  • 3
  • For what your command did: You echo'd the string to STDOUT and redirected it into .zshrc. The problem, a single redirect truncates the target file to 0 before adding the input. In your case, `>>` would have been better, it adds the input at the end of the file. See [here](https://www.gnu.org/software/bash/manual/html_node/Redirections.html) in 3.6.2 for more information. For you main problem, sorry, I have no idea how to restore files on linux :( – Byte Jan 23 '22 at 16:31
  • 1
    In the future, just use your favorite text editor to edit your file, rather than trying to append to it. – chepner Jan 23 '22 at 17:43
  • Are you on linux? You might find the default one in `/etc/skel/.zshrc` – Fravadona Jan 23 '22 at 18:23
  • @Byte thanks for the explanation! And I'm on Mac; I know it's linux based (I think) , but I thought I'd tell you just in case. Also, do you have an idea why the .zshrc file is empty but commands like "brew" and "npm" still work? – Brandon H Jan 24 '22 at 00:09
  • @Fravadona I'm on Mac. – Brandon H Jan 24 '22 at 00:09
  • @BrandonH I guess the executable for those both is somewhere in the PATH (list of folder the system looks for executables). If you type `which brew` and `which npm` you can see where executables are located. With `set | grep PATH` you can see your current list of paths. If you are on Mac, do you have by any chance a Time Machine backup? – Byte Jan 24 '22 at 11:33

0 Answers0