Bash Login prompt disappeared - bash

I recently made changes to my /etc/profile, and afterwards when I open a new tab in iTerm or Terminal I don't get a prompt. I tried reverting the changes in /etc/profile to the way I thought they were before - using Vim's undo - but I still don't get a login prompt, I just get a blank screen with a blinking cursor in the top left corner. I tried logging in as a different user, and the other user has the same problem, so I think the error is in the global bash login. /etc/motd doesn't run, but I'm not sure about the other files. Normally I would restart the computer but I have one shell that works and I'm hesitant to lose it by restarting the computer. Is there anywhere where an error would be logged? Thanks for your help,
Kevin
Here's my /etc/profile:
#put this in to try and debug, but does not show on the screen
echo "hello"
export PYTHONPATH=/Library/Python/2.6/site-packages:$PYTHONPATH
# System-wide .profile for sh(1)
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
fortune

Since when you open a new terminal it remains open, it seems that bash is still running but:
It does not show a prompt because you broke $PS1. In that case you might be still able to enter commands. export PS1='$ ' would be a good start in that case.
or
It is still doing something from /etc/profile. Either it's waiting for another process, or it has entered some kind of infinite loop - like the one caused by a shell file source loop.
Since you have a working terminal, you should check the running processes in ps before and after you start a new shell, to get an idea on what's going on.

I accidentally closed the window, and after I did I tried restarting the computer. When I logged back in the prompt displayed properly. Thanks for the help in the meantime.

Related

Terminal prompt on new Mac is not the same as on my existing Mac

MacOS Ventura 13.1
M2 Silicon
Trying to set up a new mac. On my existing Mac, I have a .zshrc, and in it, I have the following:
## begin Git branch prompt
git_branch_test_color() {
local ref=$(git symbolic-ref --short HEAD 2> /dev/null)
if [ -n "${ref}" ]; then
if [ -n "$(git status --porcelain)" ]; then
local gitstatuscolor='%F{red}'
else
local gitstatuscolor='%F{green}'
fi
echo "${gitstatuscolor} (${ref})"
else
echo ""
fi
}
setopt PROMPT_SUBST
PROMPT='%/ $(git_branch_test_color)%F{none} $ '
# add 24h time the right side
RPROMPT='%D{%m-%d-%Y %k:%M:%S}'
## end Git branch prompt
And I would get something like:
/Users/jmac/Development/repos/p1 (development) $ 02-16-2023 19:20:56
(development) is in red, because I have not checked in my changes and the full path is there for me to see.
On the new Mac, there is no .zshrc by default, so I added the code to the .zprofile file, and it's not working the same. I see the date/time on the right, but I don't see the full path and the prompt looks like this:
/Users/jmac p1 % 02-16-2023 19:20:56
Any ideas? prompt modification is not my forte.
The short answer: create a ~/.zshrc file and move that code into it.
The slightly longer answer: something is overriding the value in the PROMPT variable. There isn't anything in the default zsh installation that'll turn the $ in your prompt into a %.
That 'something' could be in a few different forms. There may be code that is modifying the PS1 variable, which is essentially a synonym for PROMPT. Or there may be something hidden in scripts or functions called from ~/.zprofile (for example, oh-my-zsh does this, albeit usually from ~/.zshrc).
Some options
Try to trace what's happening in the zprofile file. One way to do that is to run these commands:
setopt xtrace
. ~/.zprofile
The main challenge here is often the sheer volume of the output; it may be difficult to find the spot where the prompt is being set.
Move the PROMPT assignment to the bottom of ~/.zprofile. Then your assignment should override whatever is setting the value earlier in the process.
Move the PROMPT assignment into ~/.zshrc. This is a better place for the assignment anyway, since .zshrc is only loaded for interactive shells, and setting the prompt is only used in interactive shells.
The code in ~/.zshrc is loaded after the code in ~/.zprofile, so this has a similar effect to the prior option.
If none of these options have any effect, then you'll need to look for other startup files, e.g. ~/.zlogin. There's a nice overview of how the various dot files are handled in zsh in this answer.

vscode integrated terminal throwing bash error - echo: command not found

On my Macbook, the integrated terminal in VSCODE which is using bash shell is throwing the error "bash: :echo: command not found" as soon as I open it and on every command that I execute in it.
But I dont see this error in my iterm or Terminal though. They both work fine. I am getting this error only in VSCode integrated terminal
It was not happening previously. I am not sure what got changed recently.
I checked if the same issue is happening in iterm and Terminal also or not. But it doesn't happen in them.
Checked the .bash_profile and .bashrc files. But they seem to be fine.
Only place I can find echo command in my bash_profile:
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007";':"$PROMPT_COMMAND";
fi
.bashrc doesn't contain any echo commands
Please let me know why this error is coming in vscode integrated terminal only and how to fix it.
Instead of this:
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007";':"$PROMPT_COMMAND";
Try this one:
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"';

Bash aliases not recognized after uninstalling oh my zsh

After I attempted to uninstall oh-my-zsh, I am getting the error
/Users/Thomas/.zshrc:source:56: no such file or directory: /Users/Thomas/.oh-my-zsh/oh-my-zsh.sh
This issue indicates that the original shell needs to be reverted back to, however the provided command
chsh -s /bin/bash
is not working. I've restarted my iTerm as well. And my aliases still don't work, as well as exported variables such as $JAVA_HOME return empty, even though they are properly set using my former .bash_profile. Also rather than ending with a ~ my terminal prompt ends with a %
Thomas%
How can I revert?
One detail, when I attempted the uninstall via uninstall_oh_my_zsh I mistyped my password. Rather than prompting me again, it looked as though it went ahead and completed the uninstall, but maybe some component of it didn't complete properly.
Make sure you have Brew installed.
Enter brew remove zsh into the terminal then reset your terminal, it should reconfigure back to your original shell.
For this kind of error, you need to check if you set the default bash to zsh in .bashrc file. So, if there is any, just comment them out.
Example for mine.
#Launch Zsh
if [ -t 1 ]; then
exec zsh
fi
So, you just need to comment that out.
#Launch Zsh
#if [ -t 1 ]; then
#exec zsh
#fi

Zsh show fail every time when I open my terminal

I'm using a Mac with OS X Yosemite and Zsh.
By accident,I delete the content of three files below:
.bashrc
.bash_profile
.profile
After that ,when I open my terminal.
The Zsh will show fail under the last login information,it confused me ,and I want to know why.
You might want to look at a duplicate question: Zshell starts up with exit status of 1 after uninstalling RVM
It has an answer that solved the issue for me:
I found a .zlogin file on my system that contained some rvm-related code. I've deleted the code, and the problem is solved!
Zsh (by default) doesn't read from .bashrc, .bash_profile, or .profile, so the contents of these files shouldn't matter. You also didn't mention which .bashrc, .bash_profile, and .profile were erased… These files exist in both your /Users/username directory and /etc. The files sourced by zsh at startup are listed in the OS X zsh man page (man zsh in a terminal) under "STARTUP/SHUTDOWN FILES". The only reason it would call one of the previously mentioned files is if they were explicitly sourced in one of the default files.
My suggestions:
Check the contents of /etc/zshenv (this is the only zsh-specific file in my etc directory). Mine has only the following:
# system-wide environment settings for zsh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
Can you log in at all using zsh? If not, can you log in using another shell? You can do this in the OS X Terminal.app by going to Preferences -> General and changing the option for "Shells open with:" from "Default login shell" to Command (fill in another shell, i.e., /bin/bash or /bin/sh). If you can log in with any shell, try the following solution from this question:
Looking for the error
All shell output goes to the terminal, so you could just redirect it
when starting it. As you are looking for error messages during
initialisation, I'd suggest the following procedure:
Disable the problematic configurations
Open a terminal
Check the value of SHLVL: echo $SHLVL
Re-enable the configurations
Start a new z-shell from within the running shell with zsh 2> zsh-error.log, this redirects stderr to the file 'zsh-error.log'.
Check the value of SHLVL again. If it is bigger then previous value then exit the current shell (exit). (Explanation below)
Have a look at 'zsh-error.log' in the current directory.
If 'zsh-error.log' does not show anything, you may want to run zsh -x
2> zsh-error.log in step 5 instead. This provides a complete debug
output of anything zsh does. This can get quite huge.
As the answer suggests, those logs can get enormous if you are sourcing man files at startup. Just a bare shell should result in a reasonably small log file.
Finally, you can retrieve a list of all the files sourced by zsh on startup by running zsh -o sourcetrace.
Hope this helps.

Unable to reset my terminal when screen is on

I have the following in my .zshrc
if [[ $STY = '' ]] then screen -xR; fi
I made a few changes to my .zshrc.
I run unsuccessfully to see changes
reset
I also restarted my shell unsuccessfully to see the changes.
This suggests me that the screen needs to be restarted somehow.
How can you restart screen such that I see the changes in my .zshrc?
source ~/.zshrc
Also maybe killall screen, then just start screen again?

Resources