Clean up terminal misstakes [closed] - bash

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I am new to the terminal and was trying to install Java.
Also attempted to use homebrew, have since uninstalled.
Now everytime I open the terminal I have three lines
-bash: /opt/homebrew/bin/brew: No such file or directory
-bash: nexport: command not found
-bash: nexport: command not found
How do i remove?
Thanks

Find the Cause
First you should find the source of those commands that are automatically executed every time you log in. Usually there are files that are being executed after every login, depending on your OS it can be a bash script like bashrc in your home directory.
So first try to find the file where these commands are executed but fail:
cd ~ && grep -rnw 'nexport'
This should give you the file where nexport is executed like /home/user/bash_profile
If it does not find any file try this:
cd / && grep -nwirl 'nexport' 2>&-
This searches the whole system for nexport and prints all files where it occurs. (the extra parameter il will suppress all access-denied errors)
Same for brew (obviously)
Change affected file(s)
If you found a file, for example lets say its /home/user/bashrc assuming you have rights to write this file
type:
nano /home/user/bashr
to start editing this file using the easy-to-use, mostly preinstalled nano-editor
When editing the file type CTRL+W to start search mode and type nexport and press Enter.
It should jump to the line where nexport occurs. If it's the line you want to remove just go to its beginning and add a #.
Example:
/home/user/bash_rc#line:72
nexport foo/bar
change to:
#nexport foo/bar
to comment it out (always better than removing)
Press CTRL+X to save and try re-login.

When you installed Homebrew and then some of its packages, several configuration files have probably been modified. You need to restore them. Look maybe at /etc/profile, /etc/bashrc, /Users/<yourself>/.bashrc (replace <yourself> by your username), /Users/<yourself>/.bash_profile and /Users/<yourself>/.profile.
How to check? Try something like this:
$ grep -El '(brew|nexport)' /etc/{bashrc,profile} ~/{.bashrc,.bash_profile,.profile}
If something shows up you found the culprit. By the way, did you search the Homebrew documentation for "uninstall"?

Related

How to open Windows file editing app from WSL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 months ago.
Improve this question
This answer states that the following will be possible:
For example, from the WSL command line you'll be able to type code /mnt/c/Users/username/src/windows-file.txt to open a Windows file in
VS Code, or type code /home/username/src/linux-file.txt to open a
Linux file in VS Code.
is it already possible with the newest WSL 2 and Windows 11 21H2?
At this point what I can do from inside WSL is to open the folder like this:
explorer.exe .
Which is already pretty awesome. But it would be even better to instead of running:
nano myfile.txt
open the file in Notepad++:
notepadpp myfile.txt
Sure, you can run any Windows executable this way.
notepad.exe myfile.txt will work, for example.
If your Notepad++ is in your PATH, then notepad++.exe would work too - mine isn't, though, so I have to use the full path:
/mnt/c/Program\ Files/Notepad++/notepad++.exe myfile.txt
You can of course create a shell script or an alias to shorten this command.
Just note that if you specify a file with a path then you will have an issue because the Linux path is passed verbatim to the Windows executable, but that can be fixed with wslpath.
Here is an example shell script that you could put into ~/bin/notepadpp for example:
#!/bin/bash
/mnt/c/Program\ Files/Notepad++/notepad++.exe "$(wslpath -w "$1")"

Export command not found on mac terminal [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I added something to my bash_profile while trying to add Playframework to my path and something got messed up badly.
I added the following line to my .bash_profile
export PATH=$PATH:the path to my play excitable
then I saved everything and restarted my terminal. I can no longer do anything from my terminal. I can't cd into any directory, I can no longer find java, I can't open vi or nano.
I found this thread on SuperUser that suggested opening a different terminal and changing the bash profile.
I tried opening bash by typing
/bin/bash
and I was successfully able to open another terminal but I still don't have access to any of the regular unix commands. I still wasn't able to open vi or nano to remove the line that is causing the problem.
I tried downloading a new terminal application without any luck.
I tried turning on hidden files so that I can just change the file with a text editor by running the following command:
defaults write com.apple.finder AppleShowAllFiles TRUE
but since my terminal isn't working that didn't work either.
How can I fix my computer.
While this is offtopic for stackoverflow, it's also pretty simple to fix:
Start Terminal.app.
Reset $PATH:
$ export PATH=/bin:/usr/bin:/usr/local/bin
Fix ~/.bash_profile:
$ vi ~/.bash_profile
Or you can avoid setting $PATH at all with:
$ /usr/bin/vi ~/.bash_profile

Got "permission denied" when emulating sh under zsh [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I just switched to zsh as my default Mac OS terminal shell. However, I found it won't automatically hit the ~/.profile file. After researching on Google, it looks like it can be solved by adding the following command in ~/.zprofile to emulate whatever in ~/.profile:
emulate sh -c '~/.profile'
However, I got the follwoing error when terminal starting up:
zsh:1: permission denied: /Users/XXX/.profile
Any idea why this is happening?
To accomplish your goal, you'd have to use:
emulate sh -c 'source ~/.profile' # Note the `source`; alternatively, use `.`
Without the source, ~/.profile would run in a subshell, which defeats your intent (exports wouldn't "stick"); you have to source that other file.
(The specific error you saw stems from an attempt to execute ~/.profile directly, without its being marked as executable. Note that shell profiles normally needn't be executable, because their only purpose is to be (automatically) read by a shell. It's a moot point, however, given that sourcing from within a shell is needed.)
As for what zsh initialization file to put the command in:
On macOS, if you've made zsh your default shell, then ~/.zprofile works, as all shells you'll open in a terminal will be login (zsh) shells, which will read that file.
Generally, though, ~/.zshrc is the better choice, as that file gets sourced by any interactive zsh shell, whether it's a login shell or not. It's also the file to use with the Oh My Zsh framework.
Sounds like you should be using .zshrc
Add this to ~/.zshrc:
EXPORT JAVA_HOME="whatever"
And type $ source ~/.zshrc in your terminal window, or start a new shell instance.
Follow up:
this article lists the startup files loading order which clarifies the confusion.

How to restore .bash_profile on a mac? None of my unix terminal are working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I added something to my bash_profile while trying to add Playframework to my path and something got messed up badly.
I added the following line to my .bash_profile
export PATH=$PATH:the path to my play excitable
then I saved everything and restarted my terminal. I can no longer do anything from my terminal. I can't cd into any directory, I can no longer find java, I can't open vi or nano.
I found this thread on SuperUser that suggested opening a different terminal and changing the bash profile.
I tried opening bash by typing
/bin/bash
and I was successfully able to open another terminal but I still don't have access to any of the regular unix commands. I still wasn't able to open vi or nano to remove the line that is causing the problem.
I tried downloading a new terminal application without any luck.
I tried turning on hidden files so that I can just change the file with a text editor by running the following command:
defaults write com.apple.finder AppleShowAllFiles TRUE
but since my terminal isn't working that didn't work either.
How can I fix my computer.
While this is offtopic for stackoverflow, it's also pretty simple to fix:
Start Terminal.app.
Reset $PATH:
$ export PATH=/bin:/usr/bin:/usr/local/bin
Fix ~/.bash_profile:
$ vi ~/.bash_profile
Or you can avoid setting $PATH at all with:
$ /usr/bin/vi ~/.bash_profile

Can I gedit something in Mac's Terminal [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
When I was using a Linux laptop as my dev machine, I used to do "gedit xxxx" in a Terminal. Now I just switched to MacBook, I d like to do the same thing.
I know that I can open gedit in a command line like "open gedit", but can I add the file name? Otherwise I have to use vim. I am not a fan of vim.
Add
alias gedit="open -a gedit"
to ~/.bash_profile :
Now you'll be able to gedit directly from the command line.
try:
open -a /path/to/gedit /path/to/file.txt
I added the following to my PATH:
:~/Applications/gedit.app/Contents/MacOS/
and afterwards I was able to access gedit from
the command line. One caveat: if gedit is not already running on the system, then it throws an error if I launch it from the command line. Once gedit is already running though, this works to open files in gedit from the command line.
To edit the path, open ~/.profile in an editor
I use textmate for dev, here is a tutorial how it is done for Textmate
http://manual.macromates.com/en/using_textmate_from_terminal.html
I believe the same would apply to gedit.
Hope it helps

Resources