coderofsalvation/powscript

if statements don't work if they follow a comment which contains single quote

esromneb opened this issue · 4 comments

input .pow file (please ignore my horrible ../ relative path)

#!../../../../scripts/powscript

# check newly generated file's hash
# md5sum $output_sv_test

h1=$(cat $output_sv_test | tail -n +6 | md5sum)

if $h1 is "d41d8cd98f00b204e9800998ecf8427e *-"
  echo "match"
else
  echo "blah"

output

#!/bin/bash

# Generated by POWSCRIPT (https://github.com/coderofsalvation/powscript)
#
# Unless you like pain: edit the .pow sourcefiles instead of this file

# powscript general settings
set -e                                # halt on error
set +m                                #
SHELL="$(echo $0)"                    # shellname
shopt -s lastpipe                     # flexible while loops (maintain scope)
shopt -s extglob                      # regular expressions
path="$(pwd)"
if [[ "$BASH_SOURCE" == "$0"  ]];then #
  SHELLNAME="$(basename $SHELL)"      # shellname without path
  selfpath="$( dirname "$(readlink -f "$0")" )"
  tmpfile="/tmp/$(basename $0).tmp.$(whoami)"
else
  selfpath="$path"
  tmpfile="/tmp/.dot.tmp.$(whoami)"
fi



h1=$(cat $output_sv_test | tail -n +6 | md5sum)

if $h1 is "d41d8cd98f00b204e9800998ecf8427e *-"
  echo "match"
else
  echo "blah"

# wait for all async child processes (because "await ... then" is used in powscript)
[[ $ASYNC == 1 ]] && wait


# cleanup tmp files
if ls /tmp/$(basename $0).tmp.user* &>/dev/null; then
  for f in /tmp/$(basename $0).tmp.user*; do rm $f; done
fi

exit 0

Expected output (if I remove both comments on line 3/4)

#!/bin/bash

# Generated by POWSCRIPT (https://github.com/coderofsalvation/powscript)
#
# Unless you like pain: edit the .pow sourcefiles instead of this file

# powscript general settings
set -e                                # halt on error
set +m                                #
SHELL="$(echo $0)"                    # shellname
shopt -s lastpipe                     # flexible while loops (maintain scope)
shopt -s extglob                      # regular expressions
path="$(pwd)"
if [[ "$BASH_SOURCE" == "$0"  ]];then #
  SHELLNAME="$(basename $SHELL)"      # shellname without path
  selfpath="$( dirname "$(readlink -f "$0")" )"
  tmpfile="/tmp/$(basename $0).tmp.$(whoami)"
else
  selfpath="$path"
  tmpfile="/tmp/.dot.tmp.$(whoami)"
fi



h1="$(cat "$output_sv_test" | tail -n +6 | md5sum)"

if [[ "$h1" == "d41d8cd98f00b204e9800998ecf8427e *-" ]]; then
  echo "match"
else
  echo "blah"
fi

# wait for all async child processes (because "await ... then" is used in powscript)
[[ $ASYNC == 1 ]] && wait


# cleanup tmp files
if ls /tmp/$(basename $0).tmp.user* &>/dev/null; then
  for f in /tmp/$(basename $0).tmp.user*; do rm $f; done
fi

exit 0



It seems like a comment with a single single quote breaks the if, however a comment with two single quotes does not break the if.

fcard commented

Should definitely be fixed by #38, of which I should have another update by the end of this month. The parser already handles this, I just need to make if statements work.

fcard commented

There you go.

if [ "${h1}" = 'd41d8cd98f00b204e9800998ecf8427e *-' ]; then
echo 'match'
else
echo 'blah'
fi

live_powscript02-s

I am still optimistic I can get this done by the end of the year; we'll see.

wow this is great. I also submitted a pull request with a different fix