Amber
Amber copied to clipboard
[BUG] If the result of a command is a single newline, assigning it to a variable results in an empty string
To Reproduce
A short version: amber eval 'let source = "\n"; source = trust $ echo "\$\{{nameof source}}" $; trust $ echo \$\{{nameof source}@Q} $' → '' ($'\n' is expected)
Longer:
fun print_h(text) {
trust $ echo \$\{{nameof text}@Q} $
}
let source = "\n"
// original
print_h(source)
// assign
source = trust $ echo "\$\{{nameof source}}" $
// should be the same as the original
print_h(source)
Unexpectedly, the source is replaced with an empty string.
$'\n'
''
Expected behavior
$'\n'
$'\n'
Additional context
- Here is the transpiled result of a short version:
echo 'let source = "\n"; source = trust $ echo "\$\{{nameof source}}" $; trust $ echo \$\{{nameof source}@Q} $' | amber build - -
#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
# version: 0.4.0-alpha
# date: 2024-12-24 22:10:02
__0_source="
"
__AMBER_VAL_0=$(echo "${__0_source}")
__AS=$?
__0_source="${__AMBER_VAL_0}"
echo ${__0_source@Q}
__AS=$?
if __AMBER_VAL_0=$(echo "${__0_source}") is replaced with __AMBER_VAL_0="$(echo \"${__0_source}\")", the problem disappears.
- This is not related to
IFS.
is this what you mean?
let test = trust $echo$;
assert_eq(test, "\n"); // fails
Yes, that is shorter. 👍