0

I do realise that I've written code for bash. However it's using /bin/sh in this case. How do I re-write this.

This:

Step 8/17 : RUN if [ "$KEY" == "" ] ; then echo "SSH key is not set, aborting" ; exit 1 ; else echo "SSH key is set" ; fi

Results in:

/bin/sh: 1: [: unexpected operator

And this:

Step 7/15 : RUN if test "$KEY" == "" ; then echo "SSH key is not set, aborting" ; exit 1 ; else echo "SSH key is set" ; fi

Results in:

/bin/sh: 1: test: unexpected operator
basickarl
  • 37,187
  • 64
  • 214
  • 335
  • It's not the one-liner that's the problem, it's the `==`. The only POSIX-defined string comparison operator is `=`; see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html. – Charles Duffy Feb 22 '18 at 15:34
  • ...you could have reduced it to just `test "$KEY" == ""` and gotten the same problem, thus factoring out the `if` for a tighter [mcve]. – Charles Duffy Feb 22 '18 at 15:35
  • @CharlesDuffy By all means do so, but first point to where because I couldn't find any that had examples for one liners. – basickarl Feb 22 '18 at 15:36
  • ...but you can reproduce the problem *without* having it be a one-liner. The "one-liner" aspect of this was a red herring, and further testing would have allowed you to discard it as an essential element of the issue. – Charles Duffy Feb 22 '18 at 15:37
  • @CharlesDuffy So multiple line can be written as one liners, is it just to remove the line break? (I don't sit with shell scripting often as you can probably tell) – basickarl Feb 22 '18 at 15:38
  • Just remove the line breaks and replace them with `;`s in places where they were syntactically necessary (and where no `;` or `&` existed before -- you can't double up command separators), and yes, you can transform any multi-line code in bash to a one-liner. – Charles Duffy Feb 22 '18 at 15:40
  • @CharlesDuffy Thank you! I did not know this and I'm probably not the only one who didn't. I'll go read the other questions now :) – basickarl Feb 22 '18 at 15:41

0 Answers0