I have a strange problem with my Ubuntu terminal: when I open it instead of seeing my username I see this:
32m]u#h[033[00m]:[033[01: command not found
31m]w[033[00m]$: command not found
’[033[01
Strangely enough bash commands work normally, the terminal just does not show my username or the current path. I googled, but was unable to find any answers. The most recent changes I made on my computer involved installing RVM (Ruby Version Manager) and manually editing the PATH to add RVM in files: .bash_profile, .profile and .bashrc, but after that it all worked normally, so I am not really sure that could be the reason.
It looks like you've edited the PS1 variable by mistake when modifying the ~/.bashrc, which controls the prompt layout. You'll need to edit your ~/.bashrc and replace it with the following default.
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u#\h:\w\$ '
fi
For more information on other changes you can make to your prompt have a look at Customising Bash Prompt. The change wouldn't appear immediately after modifying the file because bash doesn't reload it's configuration once you've changed the file automatically. You'll either need to exit the shell and start a new one or reload the configuration using
. ~/.bashrc
The . at the begining is needed, it's shorthand for the source command.
Related
I have a configuration file setup in .bashrc which I would like to apply to all terminals opened automatically in my jupyterlab.
Currently jupyterlab terminals start like this, without any of the configuration in my .bashrc file.
If I simply type bash and hit enter it does exactly what I want. Like below.
I would like for it to automatically open like this.
How can this be achieved?
Here is a very similar question.
But none of the solutions work, I mean it does open bash, not shell, so I'm not sure if that solution is what I'm looking for. But I've changed my tornado settings, I've added the environment variable SHELL=/bin/bash but none of it has any affect. (I've obviously restarted jupyterhub each time to see the effect.
Here is my jupyterhub start file 'jupyterhub.service', located in '/etc/systemd/'.
[Unit]
Description=Jupyterhub
After=syslog.target network.target
[Service]
User=root
Type=simple
Environment="PATH=/anaconda3/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
Environment="SPARK_HOME=/spark-2.3.2-bin-hadoop2.7/"
Environment="SHELL=/bin/bash"
ExecStart=/anaconda3/bin/jupyterhub -f /etc/jupyter/jupyterhub_config.py
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
Based on this github issue, bashrc needs to be sourced from profile.
I've confirmed this works by adding the following to /home/jovyan/.profile:
bash
source /home/jovyan/.bashrc
You could try creating a file
$HOME/.bash_login
and source .bashrc from there
source $HOME/.bashrc
and see if it does what you wanted.
Let me do some wild guess for what happened:
1. Config issue
As one of the comment said, change jupyter_notebook_config.py to include
c.NotebookApp.terminado_settings = {'shell_command': ['/bin/bash', '--login', '-i']}
The shell_command should be an array of three strings. See https://github.com/jupyterlab/jupyterlab/issues/4042
2. Your id or your shell
Check these right after you launch the terminal
$ whoami
$ echo $SHELL
to see you have the right user and right shell. If your user is not right, it is expecting the .bashrc in a different user's home directory. If your shell is not right, e.g., /bin/sh instead of /bin/bash (which in fact are often hard-link of each other), it will not read .bashrc
If so, try to see if your $SHELL env variable as seen by Jupyter is correct. Jupyter should use that if you didn't specify shell_command as above
3. Jupyter may be giving you a non-interactive shell
If your bash really doesn't read your .bashrc, it may be invoked as non-interactive shell (I don't know how). To check you can try run this:
$ ls
$ !!
The first ls command can be any command. The second !! is to use bash's history expansion to recall the last executed command. If will not substitute if it is not an interactive shell.
I don't expect that and I don't know how to fix if this happens.
I have the very same problem when configuring JupyterLab (similar to JupyterHub) as a Systemd-Service.
First Solution
(Please first try the second solution.)
We can address the problem by change the default configuration in jupyter_notebook_config.py (as one of the comment and answer said, but the conclusion/solution is just the reverse.)
The related comment:
The file jupyter_notebook_config.py is located at $HOME/.jupyter/. If it does not exist, it can be generated by running:
jupyter lab --generate-config
After this file is located, we modify the content as follows:
# This is for Jupyter Notebook
# c.NotebookApp.terminado_settings = {'shell_command': ['/bin/bash']}
# This is for JupyterLab/JupyterHub
c.ServerApp.terminado_settings = {'shell_command': ['/bin/bash']}
Notably, the options '--login', '-i' mentioned in above comment and answer prevent the terminal loading .bashrc.
Without these options, the shell looks like (which is expected):
(base) [ml#soc3 /]$ python --version
Python 3.9.5
While with these options, the shell looks like (not initilized with .bashrc):
bash-4.2$ python --version
Python 2.7.5
Second Solution
create or edit the ~/.bash_profile file to automaitically load ~/.bashrc:
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
After reading more about login and interactive shell, I found that the default behavior of Jupyter's terminal is login and interactive, and it will source the ~/.bash_profile if the file exists (usually, it will load the ~/.bashrc file). My problem is that I created a new user for running JupyterLab, while the default ~/.bash_profile is not created for this user, and hence ~/.bashrc will not be sourced. Furthermore, I have previously run JupyerLab with root user, which has the mentioned configuration files, thus the JupyerLab terminal works well.
I think it is more sounded. Though the first solution works, why it works is not clear to me.
Having just installed VScode I have noticed as it uses Bash by default on OSX, with the shell's default prompt of bash-3.2$; consequently, I cannot see the current working directory. It means having to type 'pwd' and 'ls' quite frequently which is obvious quite tedious.
I have tried changing the default shell in the settings to
"terminal.integrated.shell.osx": "/Applications/Utilities/Terminal.app"
or
"terminal.integrated.shell.osx": "/Applications/iTerm.app"
This doesn't seem to work, have I made a mistake here?
I would also like to know if I am limited to bash, can I configure it to display the working directory instead of simply bash-3.2$ ?
See this screenshot of how the VSCode integrated terminal looks by default
Thanks in advance!
I use Ubuntu, and only add the following lines to the end of ~/.bashrc:
if [ "$TERM_PROGRAM" = "vscode" ]; then
PS1='\$ '
fi
Try it and let me know if it works on your OS.
You can set your prompt to contain the current working directory by defining PS1 as follows:
PS1="\w $"
The $ is just some visual sugar. There all manner of things you can have your prompt display. Put the definition in your ~/.bashrc or ~/.profile for it to be set when you login.
Check out the Controlling the Prompt section of the GNU Bash manual for details.
If you are not accustomed to editing your bash init files you can do it with Visual Studio Code by going to View->Command Palette and execute the following command (one-time only):
Install 'Code' command in path
Then open the integrated terminal and type the following:
code ~/.bashrc
Then add the PS1 definition to the bottom of that file.
So I'm installing some things for coding and personal usage, and I need to run this in the terminal (I'm on Mac if you didn't read the title).
~/.bash_profile
It just says permission denied, Im running OSX 10.8.4 Mountain Lion. How do I bypass this?
On MacOS: add source ~/.bash_profile to the end of ~/.zshrc.
Then this profile will be in effect when you open zsh.
You would never want to run that, but you may want to source it.
. ~/.bash_profile
source ~/.bash_profile
both should work. But this is an odd request, because that file should be sourced automatically when you start bash, unless you're explicitly starting it non-interactively. From the man page:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
If you change .bash_profile, it only applies to new Terminal sessions.
To apply it to an existing session, run source ~/.bash_profile. You can run any Bash script this way - think of executing source as the same as typing commands in the Terminal window (from the specified script).
More info: How to reload .bash_profile from the command line?
Bonus: You can make environment variables available to OSX applications - not just the current Bash session but apps like Visual Studio Code or IntelliJ - using launchctl setenv GOPATH "${GOPATH:-}"
As #kojiro said, you don't want to "run" this file. Source it as he says. It should get "sourced" at startup. Sourcing just means running every line in the file, including the one you want to get run. If you want to make sure a folder is in a certain path environment variable (as it seems you want from one of your comments on another solution), execute
$ echo $PATH
At the command line. If you want to check that your ~/.bash_profile is being sourced, either at startup as it should be, or when you source it manually, enter the following line into your ~/.bash_profile file:
$ echo "Hello I'm running stuff in the ~/.bash_profile!"
No need to start, it would automatically executed while you startup your mac terminal / bash. Whenever you do a change, you may need to restart the terminal.
~ is the default path for .bash_profile
I was getting this error on zsh(mac os Big Sur 11.3), This is how i solved this :-
Go to Terminal.
cd /users/<yourusername>
Once you reach here issue a command :
ls -al
You will see a lot of files and one specific file .zprofile. This is your user profile. We need to edit this.
After this we need to edit the file. Issue the below command :
nano .zprofile
Once you issue this command file will be opened for edit. Add the path details for maven.
M2_PATH="/Users//code/apache-maven-3.8.1/bin" //add your path of maven diretory
PATH="${PATH}:${M2_PATH}"
export PATH
press ctrl + X and save the file.
Issue command after saving the file :
source .zprofile
Once done, you will be able to run the mvn command.
If the problem is that you are not seeing your changes to the file take effect, just open a new terminal window, and it will be "sourced". You will be able to use the proper PATH etc with each subsequent terminal window.
How can I reload file .bash_profile from the command line?
I can get the shell to recognize changes to .bash_profile by exiting and logging back in, but I would like to be able to do it on demand.
Simply type source ~/.bash_profile.
Alternatively, if you like saving keystrokes, you can type . ~/.bash_profile.
. ~/.bash_profile
Just make sure you don't have any dependencies on the current state in there.
Simply type:
. ~/.bash_profile
However, if you want to source it to run automatically when terminal starts instead of running it every time you open terminal, you might add . ~/.bash_profile to ~/.bashrc file.
Note:
When you open a terminal, the terminal starts bash in (non-login) interactive mode, which means it will source ~/.bashrc.
~/.bash_profile is only sourced by bash when started in interactive login mode. That is typically only when you login at the console (Ctrl+Alt+F1..F6), or connecting via ssh.
If you don't mind losing the history of your current shell terminal, you could also do
bash -l
That would fork your shell and open up another child process of bash. The -l parameter tells Bash to run as a login shell. This is required, because .bash_profile will not run as a non-login shell. For more information about this, read here.
If you want to completely replace the current shell, you can also do:
exec bash -l
The above will not fork your current shell, but replace it completely, so when you type exit it will completely terminate, rather than dropping you to the previous shell.
You can also use this command to reload the ~/.bash_profile for that user. Make sure to use the dash.
su - username
I like the fact that after you have just edited the file, all you need to do is type:
. !$
This sources the file you had just edited in history. See What is bang dollar in bash.
You just need to type . ~/.bash_profile.
Refer to What does 'source' do?.
Save the .bash_profile file
Go to the user's home directory by typing cd
Reload the profile with . .bash_profile
Add alias bashs="source ~/.bash_profile" into your Bash file.
So you can call bashs the next time.
If the .bash_profile file does not exist, you can try to run the following command:
. ~/.bashrc
or
source ~/.bashrc
instead of .bash_profile.
You can find more information about bashrc.
Use
alias reload!=". ~/.bash_profile"
Or if want to add logs via functions:
function reload! () {
echo "Reloading bash profile...!"
source ~/.bash_profile
echo "Reloaded!!!"
}
While using source ~/.bash_profile or the previous answers works, one thing to mention is that this only reloads your Bash profile in the current tab or session you are viewing. If you wish to reload your bash profile on every tab/shell, you need to enter this command manually in each of them.
If you use iTerm, you can use CMD⌘ + Shift + I to enter a command into all current tabs. For terminal it may be useful to reference this issue;
I use Debian and I can simply type exec bash to achieve this. I can't say if it will work on all other distributions.
I am running macOS v10.12 (Sierra) and was working on this for a while (trying all recommended solutions). I became confounded, so I eventually tried restarting my computer! It worked.
My conclusion is that sometimes a hard reset is necessary.
Simply re-sourcing the file won't "reload" in the sense that something is first unloaded, then loaded again. If that is what you want you can do:
hash -r && _SHOW_MESSAGES=1 exec -a -bash bash
I don't know what has happened, but in my Terminal on Mac OSX 10.5 it can no longer find my sudo command, or find command, etc. They are there because if I put /usr/bin/sudo or /usr/bin/find it works fine...
My .bash_login file looks like this:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin$PATH"
My .bash_profile file looks like this:
export PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:/Library/Python/2.5/site-packages/django_trunk/django/bin:/usr/local/mysql/bin:/usr/bin/sudo$PATH"
I'll say now, I don't really know what I'm doing with the Terminal. I'm just a beginner to it all, and I must of done something for the environment variables (is that what they're called?) to be lost. I presumed I'd just have to make sure the /usr/bin/ path is in my bash files, but they are, and it doesn't seem to work. Please help!
Also, when I do use the /usr/bin/find command, it says "Permission denied" to me, even though I am logged into Mac OSX as the System Administrator account. I don't understand.
Any help would be grand. Thank you - James
It looks like both of your PATH exports are malformed:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin$PATH"
The end bit there won't work. It should be:
export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:$PATH
Notice the colon before '$PATH'? It's important ;)
Also, the double quotes are not necessary.
If this doesn't work, we will need more information. It is possible that something else is modifying your path even after your shell configurations are loaded.
Can you post the results of:
$ echo $PATH
Configuration files are not always a good indication of the current environment variables, since they are modified by many programs and files, all across your system. To see all of your environment variables, you can run:
$ env
This should fix the problem completely and permanently.
first, export environment paths by using below command in the terminal.
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
now you have the commands you want. (eg. try ls. You'll see the command is working). But this is only for the current session. If you close the terminal and open a new one, you will have the previous issue. To make this change permanent, use below command,
go to home directory
cd ~
open .bash_profile file in nano / vim (I'm using nano here)
nano .bash_profile
This will open up nano editor. In a new line, paste the following;
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:$PATH
press 'control'+'o' to save (WriteOut) and 'control'+'x' to exit nano.
All done ! Now try the commands.
Check out --- http://www.sweeting.org/mark/blog/2008/05/26/mac-os-x-tip-setting-path-environment-variables
I went trough the same issue and here is how I solved it.
First of all I reverted the file to its original doing this way
/usr/bin/nano ~/.bash_profile
In my case I was not able to make work any command alias. Even vi or vim didnt work without specifying the full path of that command.
If nano is not installed just replace nano in the command by the editor installed
After that just restart the computer. In my case as I said bellow I could not use any command. When trying to do /usr/bin/source ~/.bash_profile
that command failed. So I had to restart the OS and it worked