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
2087
votes
46 answers

How do I exclude a directory when using `find`?

How do I exclude a specific directory when searching for *.js files using find? find . -name '*.js'
helion3
  • 34,737
  • 15
  • 57
  • 100
2006
votes
51 answers

How can I count all the lines of code in a directory recursively?

We've got a PHP application and want to count all the lines of code under a specific directory and its subdirectories. We don't need to ignore comments, as we're just trying to get a rough idea. wc -l *.php That command works great for a given…
user77413
  • 30,205
  • 16
  • 46
  • 52
1926
votes
12 answers

Check existence of input argument in a Bash shell script

I need to check the existence of an input argument. I have the following script if [ "$1" -gt "-1" ] then echo hi fi I get [: : integer expression expected How do I check the input argument1 first to see if it exists?
user775187
  • 22,311
  • 8
  • 28
  • 36
1839
votes
39 answers

How do I prompt for Yes/No/Cancel input in a Linux shell script?

I want to pause input in a shell script, and prompt the user for choices. The standard Yes, No, or Cancel type question. How do I accomplish this in a typical bash prompt?
Myrddin Emrys
  • 42,126
  • 11
  • 38
  • 51
1810
votes
11 answers

Difference between sh and Bash

When writing shell programs, we often use /bin/sh and /bin/bash. I usually use bash, but I don't know what's the difference between them. What's main difference between Bash and sh? What do we need to be aware of when programming in Bash and sh?
Weiwei Yang
  • 18,261
  • 3
  • 15
  • 10
1741
votes
29 answers

How to convert a string to lower case in Bash

Is there a way in bash to convert a string into a lower case string? For example, if I have: a="Hi all" I want to convert it to: "hi all"
assassin
  • 19,899
  • 10
  • 30
  • 43
1730
votes
40 answers

How to specify the private SSH-key to use when executing shell command on Git?

A rather unusual situation perhaps, but I want to specify a private SSH-key to use when executing a shell (git) command from the local computer. Basically like this: git clone git@github.com:TheUser/TheProject.git -key…
Christoffer
  • 25,035
  • 18
  • 53
  • 77
1469
votes
18 answers

YYYY-MM-DD format date in shell script

I tried using $(date) in my bash shell script, however, I want the date in YYYY-MM-DD format. How do I get this?
Kapsh
  • 20,751
  • 13
  • 36
  • 44
1418
votes
27 answers

How can I declare and use Boolean variables in a shell script?

I tried to declare a Boolean variable in a shell script using the following syntax: variable=$false variable=$true Is this correct? Also, if I wanted to update that variable would I use the same syntax? Finally, is the following syntax for using…
hassaanm
  • 14,539
  • 4
  • 21
  • 20
1404
votes
24 answers

How to use SSH to run a local shell script on a remote machine?

I have to run a local shell script (windows/Linux) on a remote machine. I have SSH configured on both machine A and B. My script is on machine A which will run some of my code on a remote machine, machine B. The local and remote computers can be…
Arun
1381
votes
25 answers

Running shell command and capturing the output

I want to write a function that will execute a shell command and return its output as a string, no matter, is it an error or success message. I just want to get the same result that I would have gotten with the command line. What would be a code…
Silver Light
  • 44,202
  • 36
  • 123
  • 164
1345
votes
22 answers

Why do people write "#!/usr/bin/env python" on the first line of a Python script?

I see these at the top of Python files: #!/usr/bin/env python #!/usr/bin/env python3 It seems to me that the files run the same without that line.
john garcias
  • 13,555
  • 3
  • 16
  • 3
1340
votes
17 answers

Replace one substring for another string in shell script

I have "I love Suzi and Marry" and I want to change "Suzi" to "Sara". firstString="I love Suzi and Marry" secondString="Sara" Desired result: firstString="I love Sara and Marry"
Zincode
  • 13,441
  • 3
  • 13
  • 6
1283
votes
11 answers

Assigning default values to shell variables with a single command in bash

I have a whole bunch of tests on variables in a bash (3.00) shell script where if the variable is not set, then it assigns a default, e.g.: if [ -z "${VARIABLE}" ]; then FOO='default' else FOO=${VARIABLE} fi I seem to recall there's some…
Edward Q. Bridges
  • 16,712
  • 8
  • 35
  • 42
1256
votes
22 answers

How to call shell commands from Ruby

How do I call shell commands from inside of a Ruby program? How do I then get output from these commands back into Ruby?
CodingWithoutComments
  • 35,598
  • 21
  • 73
  • 86