diff --git a/CHANGES.md b/CHANGES.md
index 12aba8e042..b9ef99e36d 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -19,6 +19,7 @@ Language Improvements:
- fix(javascript) prevent get/set variables conflicting with keywords (#2440) [Josh Goebel][]
- bug(clojure) Now highlights `defn-` properly (#2438) [Josh Goebel][]
+- enh(bash) default value is another variable (#2439) [Josh Goebel][]
- enh(bash) string nested within string (#2439) [Josh Goebel][]
- enh(bash) Add arithmetic expression support (#2439) [Josh Goebel][]
- enh(clojure) Add support for global definitions name (#2347) [Alexandre Grison][]
diff --git a/src/languages/bash.js b/src/languages/bash.js
index 093947df27..be9c8c92fc 100644
--- a/src/languages/bash.js
+++ b/src/languages/bash.js
@@ -7,13 +7,21 @@ Category: common
*/
export default function(hljs) {
- const VAR = {
+ const VAR = {};
+ const BRACED_VAR = {
+ begin: /\$\{/, end:/\}/,
+ contains: [
+ { begin: /:-/, contains: [VAR] } // default values
+ ]
+ };
+ Object.assign(VAR,{
className: 'variable',
variants: [
{begin: /\$[\w\d#@][\w\d_]*/},
- {begin: /\$\{(.*?)}/}
+ BRACED_VAR
]
- };
+ });
+
const SUBST = {
className: 'subst',
begin: /\$\(/, end: /\)/,
diff --git a/test/markup/bash/variables.expect.txt b/test/markup/bash/variables.expect.txt
new file mode 100644
index 0000000000..708b15f2f2
--- /dev/null
+++ b/test/markup/bash/variables.expect.txt
@@ -0,0 +1,3 @@
+$A
+${B}
+${WURST:-${CARNE}}
diff --git a/test/markup/bash/variables.txt b/test/markup/bash/variables.txt
new file mode 100644
index 0000000000..eb89ed0cda
--- /dev/null
+++ b/test/markup/bash/variables.txt
@@ -0,0 +1,3 @@
+$A
+${B}
+${WURST:-${CARNE}}