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

Gaps in variable #182

Closed
tom-i opened this issue Jun 1, 2022 · 2 comments
Closed

Gaps in variable #182

tom-i opened this issue Jun 1, 2022 · 2 comments

Comments

@tom-i
Copy link

tom-i commented Jun 1, 2022

Hi,
if vod_title_original has some gaps (spaces) inside jo doesn't add whole string with gaps, just first string.

vod_title_original='The Dawns Here Are Quiet'
jo -p -n  -- -s id=$vod_id name="$vod_title" meta[alternativeName]=$(jo name="$vod_title_original")

result:

{
   "id": "1611180934340500000",
   "name": "…a jitra jsou zde tichá",
   "meta": {
      "alternativeName": "{\"name\":\"The",`
....

Without quotes:
jo -p -n -- -s id=$vod_id name="$vod_title" meta[alternativeName]=$(jo name=$vod_title_original)

{
   "id": "1611180934340500000",
   "name": "…a jitra jsou zde tichá",
   "meta": {
      "alternativeName": {
         "name": "The"
       },
....

Looks like bug for me, or have I misunderstood something? Because basic element name: shows gaps without problem.

Distro: Archlinux
jo: 1.6

@gromgit
Copy link
Collaborator

gromgit commented Jun 1, 2022

You've misunderstood bash command line expansion. From the EXPANSION section of the bash man page:

Expansion is performed on the command line after it has been split into words. There are seven kinds of expansion performed: brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, and pathname expansion.

The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fashion); word splitting; and pathname expansion.

Note that command substitution comes before word splitting. In fact, you left out some errors in your original output, that were a Big Red Flag waving you in this direction:

$ vod_id="1611180934340500000"
$ vod_title="…a jitra jsou zde tichá"
$ vod_title_original='The Dawns Here Are Quiet'

$ jo name="$vod_title_original"
{"name":"The Dawns Here Are Quiet"}

$ jo -p -n  -- -s id=$vod_id name="$vod_title" meta[alternativeName]=$(jo name="$vod_title_original")
Argument `Dawns' is neither k=v nor k@v
Argument `Here' is neither k=v nor k@v
Argument `Are' is neither k=v nor k@v
Argument `Quiet"}' is neither k=v nor k@v
{
   "id": "1611180934340500000",
   "name": "…a jitra jsou zde tichá",
   "meta": {
      "alternativeName": "{\"name\":\"The"
   }
}

You just need another pair of quotes, to protect your command substitution against word splitting:

$ jo -p -n  -- -s id=$vod_id name="$vod_title" meta[alternativeName]="$(jo name="$vod_title_original")"
{
   "id": "1611180934340500000",
   "name": "…a jitra jsou zde tichá",
   "meta": {
      "alternativeName": {
         "name": "The Dawns Here Are Quiet"
      }
   }
}

@gromgit gromgit closed this as completed Jun 1, 2022
@tom-i
Copy link
Author

tom-i commented Jun 2, 2022

Thx a lot.. helped 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants