- How do I find the version of bash I am running?
- 7 Answers 7
- Как узнать свою версию Bash
- 1.
- 2.
- 3.
- 4.
- How can I find my shell version using a Linux command?
- 4 Answers 4
- How to check Bash version
- How to check the Bash version
- How do I know if I have bash or zsh?
- Finding the version of bash and zsh
- Finding current shell
- Finding the path of bash or zsh shell
- Switching bash to zsh
- Switch zsh to bash
- Conclusion
- About the author
- Talha Saif Malik
How do I find the version of bash I am running?
(learning bash) I was trying to check the bash version so I typed /bin/bash -v . That outputted a whole lot of text to the screen (contents of .bashrc, and other files sourced from it). Could I have screwed up something (like overwriting some config files/setting incorrect environment variables etc.) due to that command? I also can’t find documentation on what the -v switch is for.
If you ran bash -v you invoked a new bash shell with verbose mode activated, so you will see verbose output for further commands (at the very minimum you’ll see printf «\033]0;%s@%s:%s\007» «$
7 Answers 7
The -v parameter for bash stands for verbose, and instructs bash to print out as much information as possible about what it is doing. On startup, it will print out all the configuration it is reading in.
To print out the version information for bash, use bash —version .
Alternatively, if you’re already running a bash shell, you can output the content of the special BASH_VERSION variable. echo «$BASH_VERSION» . There’s also a special array (BASH_VERSINFO) containing each version number in separate elements. if ((BASH_VERSINFO[0] < 4)); then echo "Sorry, you need at least bash-4.0 to run this script." >&2; exit 1; fi
The problem with this method is you cannot be 100% sure that any script, symbolic link, or any other kind of mess up configuration, who changed any environment variable at login. As I answered below, Ctrl+x Ctrl+v will show you exactly the bash version you’re currently running, regardless of any environment variable.
It’s worth pointing out that this will tell you the version of which bash (located at /bin/bash on most systems), which may be different than the version that happens to be running in some prompt or script. (For example, a script started with #!/usr/local/bin/bash might use a different version). Other methods (documented in other answers) may also be helpful.
When running bash (e.g. from gnome-terminal ) you can check value of BASH_VERSION environment variable.
$ echo $BASH_VERSION 4.2.37(1)-release
If the value is empty, you are not running bash .
This is better than just running bash —version , because it confirms that you are currently running bash, not just that you have bash installed on your system.
Beware: A set BASH_VERSION does not ensure that you are running bash : export BASH_VERSION; csh -c ‘echo $BASH_VERSION $SHELL $shell’ , so $BASH_VERSION may be set in csh as well
@Tino well, you could do a $SHELL —version , but again SHELL might be overwritten (and all shell do not support the —version flag).
$BASH_VERSION is very strongly advised over $SHELL —version . Needing this on a Mac trying to make sure I’m not using the system’s bash over a package managed (up to date) bash has $SHELL=/bin/bash , but is correctly configured and running my desired version. Can’t give another upvote here, unfortunately.
There’s a key shortcut that instructs current shell information to show up:
display-shell-version (C-x C-v) Display version information about the current instance of bash.
This is the best choice if you have messed with environment variables.
No, everything is alright. From man bash :
It is just not as silent as usual. Try
The usual —version may give you too much multi-line boilerplate so what I am using is
@wjandrea This is different from Paweł Nadolski’s answer. It runs the command in a new bash shell. One way this is useful is that it doesn’t need the shell currently being used to be bash . Another is that, even in bash , it’s possible (though not good) to set BASH_VERSION to a different value. It can even be exported as an environment variable. Yet even after running export BASH_VERSION=foobar , the method given here works, since the new bash shell resets its own BASH_VERSION automatically before performing the parameter expansion that reads it.
@EliahKagan, in my updated & upgraded installed 16.04 LTS system installed from the 16.04.1 iso file, bash —version says 4.3.48(1)-release and apt-cache policy bash says 4.3-14ubuntu1.2 and I have checked that the executable bash file comes from the package ‘bash’. How should this be interpreted? There is a similar mismatch for usb-creator-gtk , and in that case the apt-cache output is correct. — Can we conclude that the higher version number is the correct one (and someone forgot to update the other one)?
@sudodus A program’s version number can be different from the version number of the APT package it comes in. That’s what you’re seeing here. 4.3.48. is the version of Bash, 4.3-14. is the version of the bash package.
Как узнать свою версию Bash
Если у вас не работают примеры Bash кода, которые вы нашли онлайн или в учебниках, то одной из причин проблем может быть несоответствие версий. Или даже у вас может быть запущен не Bash, а одна из других многочисленных оболочек Linux.
Данная статья расскажет, как проверить используемую версию Bash и как убедиться, что вы работаете именно в Bash, а не в другой оболочке.
1.
Этот метод проверить версию Bash также позволит вам убедиться, что вы работаете именно в Bash:
Если вы используете другую оболочку, то ничего не будет выведено.
2.
Следующее сочетание клавиш покажет информацию о текущем экземпляре Bash, возможно вам будет проще его запомнить, чем имя переменной окружения:
Ctrl+x Ctrl+v
GNU bash, версия 5.0.17(1)-release (x86_64-pc-linux-gnu)
3.
Запуск bash с опцией —version:
Помните, что в этом случае версия bash будет выведена даже если в вашей текущей оболочке не используется bash, но bash установлен в системе.
4.
Если у вас система в обновлённом состоянии, то вы можете проверить версию Bash в репозиториях вашего дистрибутива — она будет соответствовать версии в вашей системе.
Для Debian, Linux Mint, Ubuntu, Kali Linux и их производных это можно сделать следующей командой:
В Arch Linux, BlackArch и их производных:
How can I find my shell version using a Linux command?
I would like to know about my shell version using a Linux command. I tried the following command, but it shows the type of the shell I am in. Command:
Notice that you could use some strange shell, even one which is not POSIX compliant (e.g. fish or es. ). You should know what shell you are using. If it is bash , indeed try bash —version . Or use your package management system ( dpkg -l bash on Debian or Ubuntu)
4 Answers 4
It depends on whether you want to know the version of your default login shell, or the version of the shell you’re currently running. They’re not necessarily the same.
For your default login shell, as the accepted answer says, $SHELL —version is likely to work. Most (but not all) shells accept a —version option. ( dash does not.) And this assumes that the value of $SHELL hasn’t been changed (there can be valid reasons to do so).
For the shell you’re currently running, if it happens to be bash you can type:
echo $ZSH_VERSION echo $ZSH_PATCHLEVEL # shows more detailed information
Again, this assumes that the relevant variable hasn’t been modified (there’s rarely any non-malicious reason to change it).
Bash in particular has an array variable $BASH_VERSINFO that gives more information in a form that’s easier to process programmatically. Printing $BASH_VERSINFO only prints the first element; to print all elements:
How to check Bash version
In this article, we cover how to check the Bash version in Linux. Not everyone wishes to interact with their operating system through a Graphical User Interface (GUI). Some find it easier to use a command-line interface. And, the utility that helps us execute commands in a shell.
The default shell in most Linux distributions is Bash or Bourne-Again Shell. Now, why is it important to know which Bash version we are currently working with?
Developers try to bring new features with every update. As newer versions are released, some existing features are removed. At the same time, new exciting features that bring efficiency to our work are added.
So, it is important to know the version of any application we are working with.
How to check the Bash version
There are three ways to check the Bash version. We will each of these next.
Method I. Use the echo command with the environment variable: BASH_VERSION.
It is worth mentioning here that, BASH_VERSION here case sensitive.
Method II. Use the option, –version
Method III. Use the keyboard shortcuts, Ctrl + x + v
For all the above methods, we get the version number in the standard output itself.
In conclusion, we have covered here how to find out the Bash version.
How do I know if I have bash or zsh?
Usually, when you heard about Linux-based programming, it is referred to as command-line interfaces, shells, and terminals. Bash is considered the most commonly used shell in this regard. However, there also exist other versions of shells, such as Z shell or Zsh.
Bash shell was introduced to replace Bourne Shell and to become the default Linux shell. Bash is capable of performing a wide range of programming solutions and automated tasks. In Linux, several other shells can perform similar tasks as bash. Zsh was created after the bash shell. It has various features that are also present in the Bash shell. However, some features make it superior to bash, such as Plugin support, Spelling correction, Themes bundle, CD automation, etc. If you are a Linux user, you do not have to install Zsh separately since it is included by default in the Bash shell.
Now, coming to the article’s main subject, how will you know that you have bash or zsh?
The answer is quite simple. Use the “–version” command to confirm the existence of both shells on your Linux system.
Finding the version of bash and zsh
Write out the below-given command to check the bash version on your system. Execution of this command will also ensure that bash exists on your system or not.
For checking zsh, utilize the below-given command:
Finding current shell
For beginners working in a terminal, sometimes it can be confusing to guess the shell they are currently working on. So we will assist you too in the process of finding the current shell.
Execute the below-given command in your shell.
If you are active in your bash shell, it will show you the “bash” resulting from the above command execution.
On the other side, for zsh, it will print out “zsh” on the terminal.
Finding the path of bash or zsh shell
To know the path of your zsh or bash shell, execute the below-given command.
Switching bash to zsh
To switch from bash shell to zsh. For that, in the terminal, we execute the “chsh” command in this way:
Now close the terminal, and reboot the system to take the effect of the changes. After reboot, open up a terminal window. Now, you are all ready to work in zsh shell.
Switch zsh to bash
To switch zsh to bash, specify “bash” in the “chsh” command and execute it on the terminal.
Again, reboot the system after closing the terminal, and after reboot, you will see that you are switched to the bash shell.
Conclusion
For Linux users, bash and zsh are extremely useful shells. Both shells offer various beneficial characteristics. Of course, the user can choose the shell he or she wants to use based on the task’s requirement, but in such case, confusion arises in the minds of beginners terminal users that whether they are working in zsh or bash? In this post, we have shown you various methods to know the question to this question. Employ any of these methods and get to know your current shell in few seconds.
About the author
Talha Saif Malik
Talha is a contributor at Linux Hint with a vision to bring value and do useful things for the world. He loves to read, write and speak about Linux, Data, Computers and Technology.