whiteinge/ok.sh

ARM / Raspberry PI - Runtime errors

Closed this issue · 8 comments

  1. JQ is installed:
raspberrypi2> jq
jq - commandline JSON processor [version ]
Usage: jq [options] <jq filter> [file...]

        jq is a tool for processing JSON inputs, applying the..
            ....

Running any command:

qx@raspberrypi2 ~ $ ok.sh list_releases toyfoundry rebadge
/usr/local/bin/ok.sh: 399: local: |: bad variable name

With debug:

qx@raspberrypi2 ~ $ ok.sh org_repos toyfoundry
ok.sh DEBUG: Running command org_repos.
ok.sh DEBUG: Formatting 0 parameters as urlencoded
/usr/local/bin/ok.sh: 399: local: |: bad variable name
ok.sh DEBUG: Processing response.
ok.sh DEBUG: Response status is: 200 OK
ok.sh DEBUG: Outputting requested header 'status_code'.
ok.sh DEBUG: Outputting requested header 'status_text'.
ok.sh DEBUG: Outputting requested header 'Link_next'.
ok.sh INFO: Remaining next link follows: 50
ok.sh DEBUG: Command org_repos exited with 0.

Any ideas would be appreciated!

Hm. It may be that the shell is choking on the | in that variable's value. It may also be that jq doesn't like the | character.

  • What shell are you using?
  • What version of jq is installed?

Try this command. It will pretty-print the JSON (instead of trying to pluck sub-values). If it works that will be telling and we can go from there.

ok.sh list_releases toyfoundry rebadge _filter='.'

Lastly, are you running stock Raspbian? I've got an old Pi that I can dig up and try there.

Thanks for the quick reply!

Shell: GNU bash, version 4.2.37(1)-release (arm-unknown-linux-gnueabihf)
JQ: 1.5

In regards to your command with the filter - it runs perfectly, so it may be jq that is choking on the pipe.
Finally, yes, this is stock Raspbian on a RPI 2.

Please let me know if I can help further.

Interesting. I would expect GNU bash and the latest jq to be middle-of-the-road safe. Not sure where the trouble is there. I dug out my pi last night so I'll give that combination a whirl and report back as soon as I can.

I was trying to think of a workaround to get you back in business until I can spin up my Pi but I can't think of a jq query syntax that doesn't involve pipes. 😛 E.g.:

ok.sh list_releases toyfoundry rebadge _filter='.[] | .["name"]'

The -j flag will at least output the full, unformatted, JSON response so you can parse with shell tools from there...

ok.sh -j list_releases toyfoundry rebadge _filter='.'

Thanks kindly. I'll be more than happy to help out if I can with the
debugging.
In the meantime, I've piped curl directly to jq:
ie: curl -s https://api.github.com/repos/toyfoundry/${1}/releases/latest |
jq -c -r '.tag_name'

Which seems to work as well, but obviously I have to hard code my
credentials in the curl string :)

On 29 September 2015 at 03:33, Seth House notifications@github.com wrote:

Interesting. I would expect GNU bash and the latest jq to be
middle-of-the-road safe. Not sure where the trouble is there. I dug out my
pi last night so I'll give that combination a whirl and report back as soon
as I can.

I was trying to think of a workaround to get you back in business until I
can spin up my Pi but I can't think of a jq query syntax that doesn't
involve pipes. [image: 😛] E.g.:

ok.sh list_releases toyfoundry rebadge _filter='.[] | .["name"]'

The -j flag will at least output the full, unformatted, JSON response so
you can parse with shell tools from there...

ok.sh -j list_releases toyfoundry rebadge _filter='.'


Reply to this email directly or view it on GitHub
#16 (comment).

Reproduced on my Pi. Seems to be a dash-ism. Also reproducible with dash on OS X.

I'm very much under the impression that assigning a variable directly (e.g., _filter=$1) should not require quoting the right-side variable while still preserving whitespace (and odd characters too?). But that is certainly not the case with dash. I'm going to investigate a touch more on the best fix and why this error isn't seen on Travis (which I thought was also using dash). I may just have to quote all the positional assignments but I'd like to rule a thing or two out first.

The good news is there's a quick workaround. Just explicitly use bash as the shell:

bash ok.sh list_releases toyfoundry rebadge

@quantum-x Thanks a bunch for the bug report!

Well done on the digging, and thank you kindly for the work around!

On 30 September 2015 at 05:56, Seth House notifications@github.com wrote:

Reproduced on my Pi. Seems to be a dash-ism. Also reproducible with dash
on OS X.

I'm very much under the impression that assigning a variable directly
(e.g., _filter=$1) should not require quoting the right-side variable
while still preserving whitespace (and odd characters too?). But that is
certainly not the case with dash. I'm going to investigate a touch more on
the best fix and why this error isn't seen on Travis (which I thought was
also using dash). I may just have to quote all the positional assignments
but I'd like to rule a thing or two out first.

The good news is there's a quick workaround. Just explicitly use bash as
the shell:

bash ok.sh list_releases toyfoundry rebadge

@quantum-x https://github.com/quantum-x Thanks a bunch for the bug
report!


Reply to this email directly or view it on GitHub
#16 (comment).

Added a test for this bug and cut 0.2.2 with the fix.