nexdrew / rekcod

docker inspect :mag: → docker run :runner:
ISC License
371 stars 32 forks source link

Escape & encapsulate special characters #24

Closed hasnat closed 6 years ago

hasnat commented 6 years ago

escaping & encapsulating some special characters or you might get -bash: !: event not found OR -bash: syntax error near unexpected token('`

nexdrew commented 6 years ago

@hasnat Hi 👋 thanks for this contribution!

Just so I'm clear, you want rekcod to better handle environment variables that contain the characters !, (, and ) in their values, specifically by escaping those characters with a backslash and/or wrapping them in double-quotes?

I wonder if there aren't other special characters that would need to be escaped as well, e.g. $ and &? I guess this depends on the shell.

Regardless I'd like to do a bit of local testing with actual Docker containers before I review or merge this. Do you have a (lightweight) image I could pull and test with? If not, I'll try out some of the usual suspects. ;)

hasnat commented 6 years ago

some characters can't be used without double quotes e.g. ! for others only escaping them was enough. you're right, I just noticed we also need to escape &, ? there could be way more than those. I can investigate later, but yes it would depend on bash/zsh/shell. feel free to add commits to this. for testing docker run command I use https://hub.docker.com/r/tianon/true/

hasnat commented 6 years ago

I havent tried but seems promising, I can convert this to use single quotes then we only need to escape single quotes

Reference: https://stackoverflow.com/a/20053121/254044

nexdrew commented 6 years ago

@hasnat I think I like the single quotes approach better, let's go with that.

hasnat commented 6 years ago

@nexdrew all yours now

nexdrew commented 6 years ago

@hasnat Released as version 2.1.0. Give it a shot and let me know how it goes. Thanks again!