Difference between sh and Bash

What is sh? sh (or the Shell Command Language) is a programming language described by the POSIX standard. It has many implementations (ksh88, Dash, …). Bash can also be considered an implementation of sh (see below). Because sh is a specification, not an implementation, /bin/sh is a symlink (or a hard link) to an actual implementation on most POSIX systems. What is Bash? Bash … Read more

source command not found in sh shell

/bin/sh is usually some other shell trying to mimic The Shell. Many distributions use /bin/bash for sh, it supports source. On Ubuntu, though, /bin/dash is used which does not support source. Most shells use . instead of source. If you cannot edit the script, try to change the shell which runs it.

What does set -e mean in a bash script?

From help set : But it’s considered bad practice by some (bash FAQ and irc freenode #bash FAQ authors). It’s recommended to use: to run do_something function when errors occur. See http://mywiki.wooledge.org/BashFAQ/105

What does set -e mean in a bash script?

From help set : But it’s considered bad practice by some (bash FAQ and irc freenode #bash FAQ authors). It’s recommended to use: to run do_something function when errors occur. See http://mywiki.wooledge.org/BashFAQ/105

How can I have a newline in a string in sh?

If you’re using Bash, the solution is to use $’string’, for example: If you’re using pretty much any other shell, just insert the newline as-is in the string: Bash is pretty nice. It accepts more than just \n in the $” string. Here is an excerpt from the Bash manual page:

Categories sh Tags

How to read a file into a variable in shell?

In cross-platform, lowest-common-denominator sh you use: In bash or zsh, to read a whole file into a variable without invoking cat: Invoking cat in bash or zsh to slurp a file would be considered a Useless Use of Cat. Note that it is not necessary to quote the command substitution to preserve newlines. See: Bash Hacker’s Wiki – Command substitution – Specialities.

Can’t run C program: “a.out: command not found”

When you type a command name (a.out is no different from any other command name in this respect), the shell searches for an executable file with that name. It performs this search using a list of directory names stored in your $PATH environment variable. You can see your current $PATH by typing at your shell prompt. A typical value might … Read more

How to cat <> a file containing code?

You only need a minimal change; single-quote the here-document delimiter after <<. or equivalently backslash-escape it: Without quoting, the here document will undergo variable substitution, backticks will be evaluated, etc, like you discovered. If you need to expand some, but not all, values, you need to individually escape the ones you want to prevent. will produce … Read more

What does the line “#!/bin/sh” mean in a UNIX shell script?

It’s called a shebang, and tells the parent shell which interpreter should be used to execute the script. Most scripting languages tend to interpret a line starting with # as comment and will ignore the following !/usr/bin/whatever portion, which might otherwise cause a syntax error in the interpreted language.