Hot answers tagged

35

I'd guess lack of features - no command history, no fancy redirection, no command line editing. BSD introduced csh the C shell for those reasons. Another factor is that the Genuine Bourne Shell was only recently available in open source form. Unless you licensed it, you couldn't distribute it. That put it out of reach for free-of-cost distros, and made it ...


20

There's no real difference in behavior. Both commands do nothing and exit with a successful status. : emphasizes doing nothing; true emphasizes the successful status. strace true works because true is both a shell builtin and an external command (/bin/true); : is only a shell builtin (there's no /bin/: -- though there could be, and probably was on very ...


18

The statement in your question is incorrect. Solaris up to version 10 is providing the legacy true Bourne shell as /bin/sh. This was done not to break compatibility with old scripts that might fail with a different shell. This choice was very frustrating otherwise though. Most if not all remaining Unix and Unix like releases, including Solaris 11, do ...


13

As far as I know the original Bourne shell couldn't be used by the BSDs and the GNU project, because of its license. Back then the original Unix had no license and the GNU project needed a shell that was under the GPL so they used the bash. The same thing is true for BSD4 the father of all BSDs. Thanks to the AT&T lawsuit they needed to rewrite all ...


13

That's not the Bourne shell, or bash emulating the Bourne shell, that's the Almquist shell, in your case probably the Debian Almquist shell (a Linux fork by Debian of BSDs' sh itself based on the original Almquist shell). In the Almquist shell (the original one and the modern versions), % is used in PATH for extra features specific to ash. Quoting from the ...


11

The short answer is no, they're not 100% compatible. But most of the shells are pretty close to the basic, so you would only rarely bump into inconsistencies. In fact, most shells differ not much by added syntax, but by some extra features like tab-completion and similar. Also, dash is sort of a descendant of ash — or port from BSD to Linux, to be ...


11

No, not all scripts intended for bash work with dash. A number of 'bashism' will not work in dash, such as C-style for loops and the double-bracket comparison operators. If you have a set of bash scripts that you want to use for dash, you may consider using checkbashisms. This tool will check your script for bash-only features that aren't likely to work in ...


10

The following detect integers, positive or negative, and work under dash and are POSIX: Option 1 echo "$1" | grep -Eq '^[+-]?[0-9]+$' && echo "It's an integer" Option 2 case "${1#[+-]}" in ''|*[!0-9]*) echo "Not an integer" ;; *) echo "Integer" ;; esac Or, with a little use of the : (nop) command: ! case ${1#[+-]} in ...


9

No, if /bin/sh is a symlink to bash bash enters just posix mode - from man bash: When invoked as sh, bash enters posix mode after the startup files are read. If you now search for posix mode at the bash manpage you'll see that some shell builtins like time or source behave differently. That is all. bashishms like writing function before declaring a ...


9

In your first example, $((X+1)) evaluates the expression X + 1 and expands to the result, which is then asigned to the variable. In the second example, $((X=X+1)) increments X by one ($((X++)) is also valid and shorter, but not necessarily supported by the shell), then expands to the new value of $X, which is the first argument to the null command, :. The ...


7

There seems to be some confusion around the Bourne shell. The Bourne shell was Unix shell decades ago, in the pre-POSIX days. Nowadays "sh" is an implementation or another of a shell that implements the POSIX specification, among which we have bash, pdksh, AT&T ksh, newer Almquist shells and their derivatives that have been made POSIX compliant ...


7

If you need a specific shell when running something from a cron job wrap it in a script and call the script from the cron. #!/bin/bash diff <(xzcat file1.xz) <(xzcat file2.xz) Cron entry * * * * * user-name /path/to/above/script.bash


7

There have been other problems. The Bourne Shell did use sbrk() instead of malloc() and this made it not very portable. After the Bourne Shell had become OpenSource via OpenSolaris, I created a hafway portable version and later a really portable version by replacing sbrk() by malloc() with the help from Geoff Collyer (the same person that helped to avoid ...


6

You can determine your default shell with the following command: grep -- "$LOGNAME" /etc/passwd | awk -F":" '{print $7}' In my machine, sh is a link to dash, try: ls -l "$(which sh)"


6

You are running sh, which in Debian links to dash. If that is not the shell you want, try typing in exec bash. dash (well, neither dash nor the original Bourne sh) doesn't use readline, which explains why you see those escape sequences when you attempt to use the arrow keys.


6

The standard construct to define a function is run_backup () { … } In ksh, bash and zsh, but not in other shells such as dash, you can define a function with function run_backup { … } What happened when you ran the script with dash was: The shell executed the $(run_backup) line, naturally resulting in the first error message since there was no ...


6

-ne only means "not equal" when it's in an if [ … ] statement. In this case -ne is an option to echo. You could just as easily use -en. From bash(1): If -n is specified, the trailing newline is suppressed. If the -e option is given, interpretation of the following backslash-escaped characters is enabled. In this example there is no comparison. ...


6

They're identical in Bash. Look at builtins/colon.def in the Bash-4.2 source code. In your command strace true you are actually running the binary /bin/true instead of the bash built-in true.


6

Yes, process substitution is a non-standard feature originated in ksh and only available in ksh, bash and zsh. On systems that support /dev/fd/n (like Debian), you can do: xzcat < file1.xz | { xzcat < file2.xz | diff /dev/fd/3 -; } 3<&0 Or you can always do: bash -c 'diff <(xzcat file1.xz) <(xzcat file2.xz)'


6

Let do a benchmark. With bash: $ strace -cf bash -c 'for i in $(seq 1 1000); do bash -c ":"; done' % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 99.12 0.376044 188 2004 1002 wait4 0.74 0.002805 3 1002 clone 0.03 ...


5

This error message comes from ash. There are several shells with a similar syntax. Ash is a relatively basic one designed for a small memory footprint and fast execution. Another common shell is Bash. Bash has more features. The syntax you posted exist only in bash (and some other shells, but not ash). In ash, you would need to write¹: day=5 while [ $day ...


5

Whether dash, bash, ksh, zsh, POSIX sh, or posh ("a reimplementation of the Bourne shell" sh) ; the case construct is the most widely available and reliable: case $1 in (*[!0-9]*|"") false ;; (*) true ;; esac


5

The POSIX standard that was derived from the Bourne Shell and it's descendant ksh88 explicitly mentions that this is not granted to work. The reason is the shell syntax: <>file opens stdin for reading and writing, and: [n]<>file opens file descriptor n for reading and writing. n in this case is a single digit. You used the number 99 and ...


4

Since you have super user access, you can just change /bin/sh. Of course you'll be affecting anything that wants to use the default shell (for example, cron scripts), so try to restore it as soon as possible. First, create the wrapper. Create in your home directory a file named mysh with this content: #!/bin/dash exec /bin/dash -x "$@" Make it ...


4

You could use the -x flag in the invoking command itself: sh -x ./script


4

If you must use dash, this will work: mkfifo file1 mkfifo file2 xzcat file1.xz >file1& xzcat file2.xz >file2& diff file1 file2 rm -f file1 file2 #remove the FIFOs


4

Dash is designed to be a minimal shell for fast script execution. Being comfortable for interactive use is very much not a design goal. If you want a fancy prompt, use a shell designed for interactive use: zsh, fish, or at least bash. The escape sequences you show are for bash. Dash does expand variables in the prompt, so you can set a prompt like this in ...


4

Process substitution is easily simulated with named pipes. mkfifo logger_input logger -t my_awesome_script < logger_input & exec > logger_input echo 1 echo 2 echo 3 In fact, named pipes are one of the mechanisms (the other being /dev/fd) with which process substitution can be implemented in bash.



Only top voted, non community-wiki answers of a minimum length are eligible