Questions tagged [shell]

The term 'shell' refers to a general class of text-based interactive command interpreters most often associated with the Unix & Linux operating systems. For questions about shell scripting, please use a more specific tag such as 'bash', 'powershell' or 'ksh'. Without a specific tag, a portable (POSIX-compliant) solution should be assumed, though using 'posix' in addition or 'sh' instead is preferable.

The term 'shell' refers to a general class of text-based command interpreters most often associated with the Unix & Linux operating systems.

Popular shells to date

  • The POSIX shell spec. (sh), a standardized shell specification derived from the Bourne shell, is not an actual shell, but the common denominator of what actual /bin/sh implementations can be expected to support across POSIX-compatible systems.
  • Almquist shell and Debian Almquist shell (dash)
  • Korn shell (ksh)
    • Public Domain Korn Shell (pdksh), not developed since 1999
    • MirBSD Korn Shell (mksh)
  • GNU Bourne again shell (bash)
  • Z Shell (zsh)
  • rc (rc)
  • C shell family

While some of these resemble each other closely, there are often subtle differences:

All of ksh93, mksh and bash are supersets of the POSIX shell, which in turn is a superset of the original Bourne Shell. By default, they support mutually incompatible extensions in syntax and behavior, but also share some extensions (beyond what POSIX offers).

The Z Shell and rc are, by default, not compatible with the POSIX shell family. Questions about the shell and code samples should be clear about the environment and the version of the shell.

Tcsh comes originally as a design improvement to the original C shell. The tcsh shell has been widely used before bash became the established shell. One major popular system implementation was the Solaris family. The shell concepts ~ (tilde for home directory), history, path expansion (globbing), directory stack and aliases all originally came from the csh.

Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin or MSYS/MSYS2 on Windows and emulate a Unix environment with complete shell capabilities or use the Windows Subsystem for Linux ("Bash on Ubuntu on Windows").

In graphical user mode, terminal emulators are used to access the shell. Examples are xterm, GNOME Terminal, and OS X Terminal.

Related tags

Reference

91989 questions
6018
votes
66 answers

How do I execute a program or call a system command?

How do I call an external command within Python as if I had typed it in a shell or command prompt?
freshWoWer
  • 61,969
  • 10
  • 36
  • 35
4361
votes
35 answers

How do I check if a directory exists or not in a Bash shell script?

What command checks if a directory exists or not within a Bash shell script?
Grundlefleck
  • 124,925
  • 25
  • 94
  • 111
3478
votes
30 answers

How to concatenate string variables in Bash

In PHP, strings are concatenated together as follows: $foo = "Hello"; $foo .= " World"; Here, $foo becomes "Hello World". How is this accomplished in Bash?
Strawberry
  • 66,024
  • 56
  • 149
  • 197
3456
votes
30 answers

How to check if a string contains a substring in Bash

I have a string in Bash: string="My string" How can I test if it contains another string? if [ $string ?? 'foo' ]; then echo "It's there!" fi Where ?? is my unknown operator. Do I use echo and grep? if echo "$string" | grep 'foo'; then echo…
davidsheldon
  • 38,365
  • 4
  • 27
  • 28
3343
votes
14 answers

How do I copy a folder from remote to local using scp?

How do I copy a folder from remote to local host using scp? I use ssh to log in to my server. Then, I would like to copy the remote folder foo to local /home/user/Desktop. How do I achieve this?
Slasengger
  • 33,707
  • 3
  • 14
  • 10
3103
votes
19 answers

What does " 2>&1 " mean?

To combine stderr and stdout into the stdout stream, we append this to a command: 2>&1 e.g. to see the first few errors from compiling g++ main.cpp: g++ main.cpp 2>&1 | head What does 2>&1 mean, in detail?
Tristan Havelick
  • 67,400
  • 20
  • 54
  • 64
2910
votes
19 answers

How can I recursively find all files in current and subfolders based on wildcard matching?

How can I recursively find all files in current and subfolders based on wildcard matching?
john
  • 33,520
  • 12
  • 45
  • 62
2839
votes
38 answers

How do I split a string on a delimiter in Bash?

I have this string stored in a variable: IN="bla@some.com;john@home.com" Now I would like to split the strings by ; delimiter so that I have: ADDR1="bla@some.com" ADDR2="john@home.com" I don't necessarily need the ADDR1 and ADDR2 variables. If…
stefanB
  • 77,323
  • 27
  • 116
  • 141
2823
votes
17 answers

How to mkdir only if a directory does not already exist?

I am writing a shell script to run under the KornShell (ksh) on AIX. I would like to use the mkdir command to create a directory. But the directory may already exist, in which case I do not want to do anything. So I want to either test to see that…
Spike Williams
  • 35,795
  • 13
  • 48
  • 60
2364
votes
16 answers

How do I set a variable to the output of a command in Bash?

I have a pretty simple script that is something like the following: #!/bin/bash VAR1="$1" MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF When I run this script from the command line and pass it the arguments, I am not…
John
  • 24,083
  • 5
  • 24
  • 25
2329
votes
38 answers

How to check if a variable is set in Bash

How do I know if a variable is set in Bash? For example, how do I check if the user gave the first parameter to a function? function a { # if $1 is set ? }
prosseek
  • 182,215
  • 215
  • 566
  • 871
2301
votes
21 answers

How to delete from a text file, all lines that contain a specific string?

How would I use sed to delete all lines in a text file that contain a specific string?
A Clockwork Orange
  • 23,913
  • 7
  • 25
  • 28
2204
votes
21 answers

Loop through an array of strings in Bash?

I want to write a script that loops through 15 strings (array possibly?) Is that possible? Something like: for databaseName in listOfNames then # Do something end
Mo.
  • 40,243
  • 37
  • 86
  • 131
2142
votes
18 answers

How to reload .bashrc settings without logging out and back in again?

If I make changes to .bashrc, how do I reload it without logging out and back in?
Jed Daniels
  • 24,376
  • 5
  • 24
  • 24
2118
votes
20 answers

How do I iterate over a range of numbers defined by variables in Bash?

How do I iterate over a range of numbers in Bash when the range is given by a variable? I know I can do this (called "sequence expression" in the Bash documentation): for i in {1..5}; do echo $i; done Which gives: 1 2 3 4 5 Yet, how can I…
eschercycle
  • 22,067
  • 4
  • 21
  • 13
1
2 3
99 100