Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] If the result of a command is a single newline, assigning it to a variable results in an empty string #646

Open
lens0021 opened this issue Dec 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@lens0021
Copy link
Contributor

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

  1. 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.

  1. This is not related to IFS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant