#154 Upgrade Script prints "Syntax error: redirection unexpected"

Closed
opened 2 months ago by jhabdas · 10 comments
jhabdas commented 2 months ago

Reported in #152. Only occurs when upgrade isn’t required. Need more info to reproduce.

Reported in #152. Only occurs when upgrade isn't required. Need more info to reproduce.
jhabdas added the
bug
label 2 months ago
briain commented 2 months ago

when running the script in zsh on ‘debian testing’ I get:

themes/after-dark/bin/upgrade: 1: themes/after-dark/bin/upgrade: Syntax error: redirection unexpected

It gives that error, however running debug mode shows that the script is doing it’s job, just annoying to get an error. One or other of us could play around with the script in our own time to fix it. My (albeit truncated) results running script with bash -x themes/after-dark/bin/upgrade: bash -x themes/after-dark/bin/upgrade

  • set -e
  • update_module after-dark
  • meta_file=themes/after-dark/data/npm/latest.json
  • ‘[’ -f themes/after-dark/data/npm/latest.json ‘]’ ++ sed -n ’s/.“version”:”([^“]).*/\1/p’
  • current_vers=8.0.0 ++ wget -qO - https://registry.npmjs.org/after-dark/latest
  • LATEST_META=‘{“name”:“after-dark”,“version”:“8.0.0”,“descrip… … + ‘[’ 8.0.0 = 8.0.0 ‘]’
  • echo ‘Did not upgrade after-dark. Already using latest version.’ Did not upgrade after-dark. Already using latest version.
  • exit 0
when running the script in zsh on 'debian testing' I get: themes/after-dark/bin/upgrade: 1: themes/after-dark/bin/upgrade: Syntax error: redirection unexpected It gives that error, however running debug mode shows that the script is doing it's job, just annoying to get an error. One or other of us could play around with the script in our own time to fix it. My (albeit truncated) results running script with `bash -x themes/after-dark/bin/upgrade`: bash -x themes/after-dark/bin/upgrade + set -e + update_module after-dark + meta_file=themes/after-dark/data/npm/latest.json + '[' -f themes/after-dark/data/npm/latest.json ']' ++ sed -n 's/.*"version":"\([^"]*\).*/\1/p' + current_vers=8.0.0 ++ wget -qO - https://registry.npmjs.org/after-dark/latest + LATEST_META='{"name":"after-dark","version":"8.0.0","descrip... ... + '[' 8.0.0 = 8.0.0 ']' + echo 'Did not upgrade after-dark. Already using latest version.' Did not upgrade after-dark. Already using latest version. + exit 0
jhabdas commented 2 months ago
Owner

When I get around to booting the RPi I’ll try running there. Otherwise you may have more luck running with bash or sh. Script is know to work with zsh shell on darwin.

When I get around to booting the RPi I'll try running there. Otherwise you may have more luck running with bash or sh. Script is know to work with zsh shell on darwin.
jhabdas added the
investigation
label 2 months ago
briain commented 2 months ago

Running command bash ./themes… I get the confirmation correctly: “Did not upgrade after-dark. Already using latest version.” The above error comes if I run sh ./themes… or just /themes/aft… Apparently some distros (ubuntu possibly) default to a dash shell which doesn’t handle <<< redirects gracefully. when I echo $SHELL I am shown /usr/bin/zsh so I doubt it’s defaulting to dash. The issue is probably where the latest-vers variable is being formed in the script and there maybe another way to create the variable. Or exec the whole script with bash exclusively? RUN [“/bin/bash”, “-c”, “bash < <(themes/after-dark/bin/upgrade)“] I’ll run some experiments and get back to you.

Running command bash ./themes... I get the confirmation correctly: "Did not upgrade after-dark. Already using latest version." The above error comes if I run sh ./themes... or just /themes/aft... Apparently some distros (ubuntu possibly) default to a dash shell which doesn't handle <<< redirects gracefully. when I echo $SHELL I am shown /usr/bin/zsh so I doubt it's defaulting to dash. The issue is probably where the latest-vers variable is being formed in the script and there maybe another way to create the variable. Or exec the whole script with bash exclusively? RUN ["/bin/bash", "-c", "bash < <(themes/after-dark/bin/upgrade)"] I'll run some experiments and get back to you.
briain commented 2 months ago

I changed the shebang from #!/bin/sh to #!/bin/bash and the error goes away. I get the desired result “Did not upgrade after-dark. Already using latest version.”

I changed the shebang from #!/bin/sh to #!/bin/bash and the error goes away. I get the desired result "Did not upgrade after-dark. Already using latest version."
jhabdas commented 2 months ago
Owner

How about this for the shebang on your environment, hoss?

#!/usr/bin/env

Also interested in your uname -a with personal deets stripped.

How about this for the shebang on your environment, hoss? ```sh #!/usr/bin/env ``` Also interested in your `uname -a` with personal deets stripped.
briain commented 2 months ago

!/usr/bin/env hangs and uses 100% of my cpu until I ctrl-c.

sh is no longer a link to bash, but to dash which doesn’t know about <<<' as it's not POSIX. There are also POSIX issues with sub-nested variables, though I think that relates more to while loops than to a simpleif` statement.

Linux debian 4.19.0-5-amd64 #1 SMP Debian 4.19.37-3 (2019-05-15) x86_64 GNU/Linux

I tried changing the <<< to << and that deleted the contents of after-dark with this error, lol: Upgrading after-dark from 8.0.2 to …

gzip: stdin: unexpected end of file tar: Child returned status 1 tar: Error is not recoverable: exiting now

Can do a pomodoro (tonight GMT) to figure how to rewrite the script if you don’t want to use #!/bin/bash.

#!/usr/bin/env hangs and uses 100% of my cpu until I ctrl-c. sh is no longer a link to bash, but to dash which doesn't know about `<<<' as it's not POSIX. There are also POSIX issues with sub-nested variables, though I think that relates more to while loops than to a simple `if` statement. Linux debian 4.19.0-5-amd64 #1 SMP Debian 4.19.37-3 (2019-05-15) x86_64 GNU/Linux I tried changing the `<<<` to `<<` and that deleted the contents of after-dark with this error, lol: Upgrading after-dark from 8.0.2 to ... gzip: stdin: unexpected end of file tar: Child returned status 1 tar: Error is not recoverable: exiting now Can do a pomodoro (tonight GMT) to figure how to rewrite the script if you don't want to use #!/bin/bash.
jhabdas commented 2 months ago
Owner

Sorry meant to postfix sh after the shebang (with literal space). >< Thanks for testing it out.

Thought I validated this script with a POSIX testing tool it’s possible I missed something (can dig up later, if needed). I’ve got a Deb box and a Raspian I can test on ready to go so we can test things out on those as well before and after any changes.

Just found this. Looks useful.

https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html

End goal is maximum portability, and my test criteria for that is usually “runs on busybox using sh”.

Thanks for your input and spotting a POSIX issue.

Sorry meant to postfix ` sh` after the shebang (with literal space). >< Thanks for testing it out. Thought I validated this script with a POSIX testing tool it's possible I missed something (can dig up later, if needed). I've got a Deb box and a Raspian I can test on ready to go so we can test things out on those as well before and after any changes. Just found this. Looks useful. https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html End goal is maximum portability, and my test criteria for that is usually "runs on busybox using `sh`". Thanks for your input and spotting a POSIX issue.
briain commented 2 months ago

Ah yes, my machine was waiting for a command after invoking the environmental variable ie #!/usr/bin/env sh. Debian systems default to dash so the error should be reproducible on either.

Ah yes, my machine was waiting for a command after invoking the environmental variable ie #!/usr/bin/env sh. Debian systems default to dash so the error should be reproducible on either.
jhabdas removed the
investigation
label 2 months ago
jhabdas commented 2 months ago
Owner

Shell Command Language

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

This chapter contains the definition of the Shell Command Language.

Shell Command Language http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html This chapter contains the definition of the Shell Command Language.
jhabdas commented 2 months ago
Owner

Fixed in master. Please feel free to test.

Fixed in `master`. Please feel free to test.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
Cancel
Save
There is no content yet.