glutanimate / PDFMtEd

View and modify PDF metadata on Linux graphically
GNU General Public License v3.0
191 stars 22 forks source link

Bug: Getting syntax error on line 170. #1

Closed E3V3A closed 10 years ago

E3V3A commented 10 years ago

Have tried this script and get syntax error on line 170. Seem to be missing something, how is that line supposed to work?

...
while IFS= read -r -d $'\0' FILE; do
    ARGS[ARGID++]="$FILE"
done < <(find "$@" -type f -print0 | sort -z)
...
glutanimate commented 10 years ago

Hi,

thanks for the report. I take it you are referring to line 170 in pdfmted-inspector? That should be proper bash syntax (process substitution redirected to stdin of a while loop), but I might be overlooking something.

Could you post the full syntax error message you are getting, please?

E3V3A commented 10 years ago
Zeile 170:   done < <$find "$@" -type f -print0 | sort -z)'

I don't think that's right, I suspect that <( should be $(, unless you're using some very unusual Bashism.

glutanimate commented 10 years ago

Yup, that's a pretty exotic - but also very useful - bashism. It's called a process substitution. I used it here to avoid running the while.. loop in a subshell which would have made it impossible to globally assign the ARGS array (shamelessly copied from this BashFAQ).

If this line is producing a syntax error it's likely due to a bash compatibility problem. What version of bash are you running? Are you sure you are using /bin/bash and not bash in sh-emulation mode?

SecUpwN commented 10 years ago

@Glutanimate, I actually had this problem first, even before @E3V3A. We know each other from the Android IMSI-Catchter Detector Project, where we actually want to use it to provide our users a convenient method to erase sensitive metadata. The way I run your script is by opening my terminal and issuing sh pdfmted-inspector mypdf.pdf. Is that correct, or is this the "emulation" you've doomed?

glutanimate commented 10 years ago

Ah, I see now. If you run the script with sh it will indeed try to emulate the sh featureset and bashisms like the one in line 170 won't work. Try running the script as follows:

pdfmted-inspector mypdf.pdf

This should also work:

bash pdfmted-inspector mypdf.pdf

E3V3A commented 10 years ago

Each one of you, please post the output of: shopt -p and set -o. That should tell you to what extent your shell settings are compatible.

SecUpwN commented 10 years ago

Thanks for helping out. When executing the script with pdfmted-inspector mypdf.pdf, I got no permission. I then set chmod +x, which makes the script behave the same way as when executing bash pdfmted-inspector mypdf.pdf: Terminal spits out yad (not sure what that shall mean at all).

Here is the output of shopt -p for @E3V3A:

SecUpwN@openSUSE:~> shopt -p
shopt -u autocd
shopt -u cdable_vars
shopt -u cdspell
shopt -u checkhash
shopt -u checkjobs
shopt -s checkwinsize
shopt -s cmdhist
shopt -u compat31
shopt -u compat32
shopt -u compat40
shopt -u compat41
shopt -u direxpand
shopt -u dirspell
shopt -u dotglob
shopt -u execfail
shopt -s expand_aliases
shopt -u extdebug
shopt -u extglob
shopt -s extquote
shopt -u failglob
shopt -s force_fignore
shopt -u globstar
shopt -u gnu_errfmt
shopt -s histappend
shopt -u histreedit
shopt -u histverify
shopt -s hostcomplete
shopt -u huponexit
shopt -s interactive_comments
shopt -u lastpipe
shopt -u lithist
shopt -u login_shell
shopt -u mailwarn
shopt -u no_empty_cmd_completion
shopt -u nocaseglob
shopt -u nocasematch
shopt -u nullglob
shopt -s progcomp
shopt -s promptvars
shopt -u restricted_shell
shopt -u shift_verbose
shopt -s sourcepath
shopt -u xpg_echo

And here the output of set -o:

SecUpwN@openSUSE:~> set -o
allexport       off
braceexpand     on
emacs           on
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
history         on
ignoreeof       off
interactive-comments    on
keyword         off
monitor         on
noclobber       off
noexec          off
noglob          off
nolog           off
notify          off
nounset         off
onecmd          off
physical        off
pipefail        off
posix           off
privileged      off
verbose         off
vi              off
xtrace          off
glutanimate commented 10 years ago

Terminal spits out yad

Probably a dependency issue. Please make sure to install all dependencies, yad in particular.

FWIW, here are the shopt and set outputs on my machine:

$ shopt -p
shopt -u autocd
shopt -u cdable_vars
shopt -u cdspell
shopt -u checkhash
shopt -u checkjobs
shopt -s checkwinsize
shopt -s cmdhist
shopt -u compat31
shopt -u compat32
shopt -u compat40
shopt -u compat41
shopt -u direxpand
shopt -u dirspell
shopt -u dotglob
shopt -u execfail
shopt -s expand_aliases
shopt -u extdebug
shopt -s extglob
shopt -s extquote
shopt -u failglob
shopt -s force_fignore
shopt -u globstar
shopt -u gnu_errfmt
shopt -s histappend
shopt -u histreedit
shopt -u histverify
shopt -u hostcomplete
shopt -u huponexit
shopt -s interactive_comments
shopt -u lastpipe
shopt -u lithist
shopt -u login_shell
shopt -u mailwarn
shopt -u no_empty_cmd_completion
shopt -u nocaseglob
shopt -u nocasematch
shopt -u nullglob
shopt -s progcomp
shopt -s promptvars
shopt -u restricted_shell
shopt -u shift_verbose
shopt -s sourcepath
shopt -u xpg_echo

$ set -o
allexport       off
braceexpand     on
emacs           on
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
history         on
ignoreeof       off
interactive-comments    on
keyword         off
monitor         on
noclobber       off
noexec          off
noglob          off
nolog           off
notify          off
nounset         off
onecmd          off
physical        off
pipefail        off
posix           off
privileged      off
verbose         off
vi              off
xtrace          off

Though I don't think that the shell options have anything to do with the problem at hand. It should just be a plain old case of dash/bash incompatibility due to executing the script with /bin/sh.

E3V3A commented 10 years ago

Thanks @Glutanimate that process substitution seem very useful:

$ diff <(cat shop1.txt) <(cat shop2.txt)
18c18
< shopt -u extglob
---
> shopt -s extglob
27c27
< shopt -s hostcomplete
---
> shopt -u hostcomplete

Where shop1.txt is from SecUpwN and yours is shop2.txt.

SecUpwN commented 10 years ago

@Glutanimate, you can close this Issue now. You script works great! Please continue to improve it. :+1:

glutanimate commented 10 years ago

Glad to hear that! If you find any other issues please don't hesitate to report them.