Which quotes to use
In the terminalela --spec which-quotes-to-use
A string's quotes depend on what it holds and where it stands.
| The text | Write | Example |
|---|---|---|
| text with a variable or a command's output | "..." | echo "built $name on $(date)" |
a regular expression, or any \, as a command's word | '...' | grep -E '^v[0-9]+\.[0-9]+$' tags.txt |
a flag holding * or ? | '...' around the whole flag | grep -r word '--include=*.mk' . |
a regular expression, or text with a ', in code | `...` | newest = re.match(`^v\d+\.\d+$`, $tag) |
a pattern with both ' and a \ | [*] and [.] for \* and \., in "..." | grep "it's [*]new[*]" notes.txt |
a ' in text | "...", or ''' for several lines | echo "it's done" |
| several lines, with variables | """, the text from the next line | body = """ ... """ |
several lines with $ in them, as written | ''', the text from the next line | script = ''' ... ''' |
- Code is an assignment, a call's argument, a condition or a
return. - In
'...'and backticks a\is a backslash. In"..."a\starts an escape, and"\d"or"\."is an error that says to use single quotes. - A
*inside a flag is a glob, aszshandfishhave it:--include=*.mkunquoted looks for files and stops when none match. ela -c '…'takes one line of code. Code of several lines goes in a here-document,ela <<'EOF'.
In "..." a variable stands as it does in code:
| To put in | Write | Not |
|---|---|---|
| an item | "$pair[0]", a computed index "${$chars[$i + 1]}" | "${pair[0]}", bash's form |
| a map's value | "$info['kind']", the key in single quotes | "${info["kind"]}": the inner " ends the string |
| text straight after a name | "${name}.d2" | "$name.d2", which reads a field d2 |
| a call's value | "${str.join($names, ", ")}" | "str.join($names, ", ")" |
+never joins text:"${a}${b}"does.
Text goes to a program's stdin through a pipe; ela has no <<<:
echo $msg | git commit -F -
(ela --spec strings)