Bash means in linux

What is Bash?

When a computer boots up, a kernel (whether it’s Linux, BSD, Mach, or NT) recognizes all the physical hardware and enables each component to talk with one another and be orchestrated by some basic software. A computer’s most basic set of instructions simply keeps it powered on and in a safe state: activating fans periodically to prevent overheating, using subsystems to monitor disk space or «listen» for newly attached devices, and so on. If this was all computers did, they’d be about as interesting as a convection oven.

Computer scientists recognized this early on, so they developed a shell for Unix computers that operates outside of the kernel (or around the kernel, like a shell in nature) and allows humans to interact with the computer whenever they want to. It was an exciting development at a time when people were feeding punchcards into computers to tell them what to do. Of all the shells available, Bash is one of the most popular, the most powerful, and the most friendly.

Bash is an application

When you start a terminal (such as the GNOME Terminal or Konsole on Linux or iTerm2 on macOS) running the Bash shell, you’re greeted with a prompt. A prompt is a symbol, usually a dollar sign ($), indicating that the shell is waiting for your input. Of course, knowing what you’re supposed to type is another matter entirely.

This probably comes across as unfriendly, but it’s actually a perfectly succinct representation of the many connotations around the term «Bash.» To many new users, there’s no separation between the concept of Bash and the concept of Linux or Unix: it’s the proverbial black-screen-with-green-text into which you’re supposed to code what your computer does next. That conflates the Bash shell with the commands you type into the shell. It’s important to understand that they’re two separate things: Bash is just an application, and its primary job is to run other applications (in the form of commands) that are installed on the same system.

[Download our free Bash cheat sheet]

You can learn Bash, but only in the context of learning the operating system that it’s running on. Without knowing commands, there’s not much you can do with Bash.

Linux commands

On Linux and Unix (such as BSD and macOS), most commands are stored by default in system directories like /usr/bin and /bin. By nature, Bash doesn’t know these commands any more than you naturally know Klingonese, but just as you can look up Klingon words, Bash can look up commands. When you issue a command to Bash, it searches specific directories on your system to see whether such a command exists. If the command does exist, then Bash executes it.

Bash is also a command, and it’s usually the default command executed when you open a terminal window or log into a text console. To find out where any command is located on your system, Bash included, you can use the which command in a terminal:

$ which bash /usr/bin/bash $ which ls /usr/bin/ls

A few commands are built into Bash. Most built-in commands are specific to Bash scripting or low-level environment settings, but a few are universally useful, such as cd (for change directory). Built-in commands don’t show up when you search for them because they don’t exist in your usual executable path:

$ which bash which: no cd in (/usr/local/bin:/usr/bin:/bin: [. ]

They’re still available, though, because they’re built into Bash, and Bash is what you’re running.

Читайте также:  Whatsapp for linux desktop

Running Bash

Most modern Linux and Unix distributions provide a Bash shell by default. They do this because Bash is well-known, and it has several convenience functions that other shells don’t. However, some systems use another shell by default. To find out whether you’re running a Bash shell, you can use the echo command along with a special variable representing the name of the currently running process:

If you’re not running Bash, but you’d like to try it, you can probably download and install Bash from your software center, software repository, or ports tree. Or you can use Chocolatey on Windows or Homebrew on macOS. If all else fails, visit the Bash homepage for more information.

Working in Bash

Bash is a legitimate interface to your computer, and it’s not just for server admins and programmers. It can be your desktop, your word processor, your graphics editing application, and much, much more. Some people use Bash more than they use desktop apps.

There are hundreds of commands available for Linux and Unix, and it might surprise you just how diverse they are. For instance, you can resize and crop photos without ever opening the photo in a viewer or editor:

$ mogrify -geometry 1600^x800 \ -gravity Center \ -crop 1600x800+0+0 myphoto.jpg

You can play music with commands like ogg123 or mpg321, convert audio with sox, adjust and edit video with ffmpeg, edit text with emacs or vim, check email with pine or mutt, browse the internet with elinks, browse files with ranger or midnightcommander, and do much, much more. It’s all done in Bash, using the commands you find on your system or in your software repository.

Bash scripting

Programming and development

One reason Bash (and Linux in general) is considered so powerful is because it’s scriptable. Anything you can type into Bash manually, you can also list in a plain-text file and have Bash run it for you. Instead of spending an afternoon manually running a hundred commands, you can script the commands and have your computer execute them while you tend to more important matters. Because nearly everything on Linux runs on top of the Bash shell, nearly everything on Linux can be scripted through Bash. While there are exceptions to this (graphical applications may have their own scripting language, for instance, or no scripting at all), scripting your OS opens up tens of thousands of possible functions you can make happen on your computer without doing them yourself.

The amount of work this saves Linux users each day is impossible to estimate. It’s not the usual automation that makes the difference, though; it’s the bespoke workflows that people invent for themselves, the things nobody else thinks need automation.

Читайте также:  Параметры настройки сети linux

When experienced users say that they want to learn Bash, if they don’t mean they want to learn Linux commands, then they probably mean that they want to improve the way they script their commands. For instance, this is an extremely rudimentary Bash script that converts a temporary file (imagine it’s a file created by a separate process) to a specific directory:

#!/usr/bin/bash cp tmp.png ~/public_html/`date +%Y%m%d`.png

That’s valid Bash. You can verify it by copying and pasting the command (the last line beginning with cp) into a terminal. As long as there’s a file called tmp.png and a directory called ~/public_html, the command works.

Learning Bash, though, is all about understanding how a simple command like this can be improved for the sake of automation. For instance, if the file tmp.png doesn’t exist, then the script fails. If this script is a key component to, for instance, a blogging site that requires a new image each day so that a custom header image can be constructed, then the script’s failure could cause catastrophic errors elsewhere. A user who knows Bash could add resiliency using Bash syntax:

#!/usr/bin/bash IMG="tmp.png" [[ -e tmp.png ]] || IMG="generic.png" cp ~/"$" ~/public_html/`date +%Y%m%d`.png

This is just one example of the process of learning to script with Bash, but it demonstrates how learning both Linux and Bash are equally useful and not entirely separate tasks.

Advantages of Bash

Bash is as powerful as other shells but adds convenience functions like the double brackets ([[ and ]]) in the sample code. These «Bashisms» are much loved by Bash users because they avoid the sometimes verbose and awkward syntax in other shells like tcsh or ash. However, they are unique to Bash and are not POSIX-compliant, which could cause compatibility issues on systems not running Bash. Then again, Bash is open source free software, so most users can install it if they need it. The lack of compatibility only forces an extra dependency and does not exclude anyone from using a script.

Learning Bash

If you want to learn Bash, you can read any number of great books on the subject.

Or, you can take an online course from EdX.org and even join in on some no-cost Red Hat courses.

Best of all, you can also play games to learn Bash.

Good luck, and happy hacking!

Creative Commons License

This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.

Источник

What Does «Bash» Mean in Linux?

You’ve probably heard of Bash, but what is it? What can it do? Find out here.

Bash Command Line in Linux

Readers like you help support MUO. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.

If you’ve been using Linux for long at all, you’ve no doubt seen the word Bash thrown around in forums and articles. It sometimes seems like a synonym for the terminal, but Bash and the terminal emulator are definitely two different applications. So what is Bash exactly? In this short article, we’ll explore what Bash is, what it does, and how you can start using it.

Читайте также:  Особенности управления памятью в linux

Bash Defined

The name Bash is an acronym for Bourne-Again SHell, a pun on the name Stephen Bourne, creator of one of Bash’s predecessors. The first beta was released in 1989, and, as of this writing, has seen its most recent update in December 2020: version 5.1.

Bash is among the most popular of shell languages, known for its combination of powerful capabilities and user-friendly commands. That’s why it’s so prolific across Linux distributions.

Bash operates not only on Linux, however; it’s also available on macOS and BSD, and you can use it on Windows through Windows Subsystem for Linux.

But to truly define Bash, we have to understand what a shell is.

A shell is an application that accepts input from a user and executes an action in response, typically communicating with the kernel to make that happen. In that way, it’s like a «shell» around the kernel.

While shells do initiate other applications through commands, they also often have interactive features themselves.

For example, when you open a Linux terminal and press the up arrow button to retrieve the last issued command, that’s a function of the Bash application. The cd command for changing directories is another very common Bash command.

Using Bash Cd Command in Linux

In addition to being an interactive application, Bash is also a scripting language. Your Linux OS in fact uses many Bash scripts in the startup process to initiate various processes.

How Can I Use Bash?

You’re using Bash anytime you use the terminal in almost any Linux system.

You can confirm that with this command, which returns the name of the shell in use:

You should get only the word bash returned. If you do, you can see the version of Bash you’re using with this command:

Your screen should look similar to this:

Checking the Version of Bash in Use

Issuing single commands in the terminal, however, is only the beginning of Bash’s uses.

Like those scripts your OS uses, you can learn to write Bash scripts that automate processes on your Linux PC that you often do manually. A skilled Bash scripter may have scripts automating hundreds of tasks a day!

So how can you learn Bash?

By writing scripts, either on your own or guided, such as in a Bash course.

For you gamers out there, you can also learn by playing a Bash game. One example is Bashcrawl, a text-based dungeon crawler that forces you to learn and recall Bash commands to progress in the game.

We also have articles here on Make Use Of that will train you to become a better Bash scripter. We can show you for example how to write for loops in Bash, or maybe turn your scripts into clickable apps.

Leveling up Your Linux Game

We’ve learned about what Bash is, its history, and how you can learn to put it to work for you.

Learning Bash is just one part, however, of getting the most out of your Linux operating system. There’s a lot more you can learn to become a Linux power user.

Источник

Оцените статью
Adblock
detector