Created
July 9, 2022 15:27
-
-
Save eqvinox/0b8ff0ad5fd7e4667d0888ba226fca9e to your computer and use it in GitHub Desktop.
POSIX shell escaping demo-sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # shell escaping "demo-sheet" | |
| # "args" just prints argv[] | |
| filename="/tmp/some file" | |
| echo 'foo echo some file contents' > "$filename" | |
| set -x | |
| args $(echo foo echo wrong) | |
| # + echo foo echo wrong | |
| # + args foo echo wrong | |
| # [1]: "foo" | |
| # [2]: "echo" | |
| # [3]: "wrong" | |
| args "$(echo foo echo better)" | |
| # + echo foo echo better | |
| # + args foo echo better | |
| # [1]: "foo echo better" | |
| args $(cat $filename) | |
| # + cat /tmp/some file | |
| # cat: /tmp/some: No such file or directory | |
| # cat: file: No such file or directory | |
| # + args | |
| args $(cat "$filename") | |
| # + cat /tmp/some file | |
| # + args foo echo some file contents | |
| # [1]: "foo" | |
| # [2]: "echo" | |
| # [3]: "some" | |
| # [4]: "file" | |
| # [5]: "contents" | |
| args "$(cat "$filename")" | |
| # + cat /tmp/some file | |
| # + args foo echo some file contents | |
| # [1]: "foo echo some file contents" | |
| args "$(cat \"$filename\")" | |
| # + cat "/tmp/some file" | |
| # cat: '"/tmp/some': No such file or directory | |
| # cat: 'file"': No such file or directory | |
| # + args | |
| # [1]: "" | |
| args `cat $filename` | |
| # + cat /tmp/some file | |
| # cat: /tmp/some: No such file or directory | |
| # cat: file: No such file or directory | |
| # + args | |
| args `cat "$filename"` | |
| # + cat /tmp/some file | |
| # + args foo echo some file contents | |
| # [1]: "foo" | |
| # [2]: "echo" | |
| # [3]: "some" | |
| # [4]: "file" | |
| # [5]: "contents" | |
| args "`cat "$filename"`" | |
| # + cat /tmp/some file | |
| # + args foo echo some file contents | |
| # [1]: "foo echo some file contents" | |
| args "`cat \"$filename\"`" | |
| # + cat /tmp/some file | |
| # + args foo echo some file contents | |
| # [1]: "foo echo some file contents" | |
| rm "$filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment