Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    # shellcheck disable=SC2064
    trap "cleanup '$SCR_IMG'" EXIT
While shellcheck can have false positives, and SCR_IMG probably doesn't have any characters which need escaping, it's not exactly wrong in this case.

The command passed to `trap` is evaluated normally, so variable expansions do take place.

    trap 'cleanup "$SCR_IMG"' EXIT
Will behave correctly, and the expansion of SCR_IMG won't be susceptible to issues relating to unquoted shell characters.

Alternatively, if you're using a modern bash (this probably won't work on a mac by default), then this is an option too:

    trap "cleanup ${SCR_IMG@Q}" EXIT


thanks for fixing and explaining that, I thought '' would work and forgot about escaping characters.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: