[BUG] If the result of a command is a single newline, assigning it to a variable results in an empty string
- 主要语言
- Rust
- 星标
- 5.2k
- 派生
- 145
- 平均合并
- 5 天 3 小时
- 30 天内合并 PR
- 7
描述
**To Reproduce**
A short version: `amber eval 'let source = "\n"; source = trust $ echo "\$\{{nameof source}}" $; trust $ echo \$\{{nameof source}@Q} $'` → `''` (`$'\n'` is expected)
Longer:
```js
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**
1. Here is the transpiled result of a short version:
```console
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.
2. This is not related to `IFS`.
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。