Amber
Amber copied to clipboard
[BUG] Breaking bash case statement when saving result to a var
Amber breaks bash case syntax by adding brackets.
Example:
let result = unsafe $case "{text}" in
*"{phrase}"*\)
echo 1
;;
esac$
evals to:
__AMBER_VAL_0=$(case "abc" in
*"a"*)
echo 1
;;
esac);
__AS=$?;
__0_result="${__AMBER_VAL_0}"
New amber code:
let text = "123"
let phrase = "12345"
let result = trust $case "{text}" in
*"{phrase}"*\)
echo 1
;;
esac$
echo result
Generates:
#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
# version: 0.4.0-alpha-33-g4772a83
# date: 2025-07-15 11:01:04
__0_text="123"
__1_phrase="12345"
__0_command="$(case "${__0_text}" in
*"${__1_phrase}"*\)
echo 1
;;
esac)"
__2_result="${__0_command}"
echo "${__2_result}"
For shellcheck:
In /home/mte90/Desktop/test.sh line 7:
__0_command="$(case "${__0_text}" in
^-- SC1009 (info): The mentioned syntax error was in this case expression.
In /home/mte90/Desktop/test.sh line 8:
*"${__1_phrase}"*\)
^-- SC1073 (error): Couldn't parse this case item. Fix to allow more checks.
^-- SC1072 (error): Expected ) to open a new case item. Fix any mentioned problems and try again.
^-- SC1085 (error): Did you forget to move the ;; after extending this case item?
For more information:
https://www.shellcheck.net/wiki/SC1085 -- Did you forget to move the ;; aft...
https://www.shellcheck.net/wiki/SC1072 -- Expected ) to open a new case ite...
https://www.shellcheck.net/wiki/SC1073 -- Couldn't parse this case item. Fi...