Created
November 10, 2012 16:51
-
-
Save thinkerbot/4051679 to your computer and use it in GitHub Desktop.
Expect - special characters without escape
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
#!/usr/bin/expect -f | |
############################################################################# | |
# | |
# Arguments passed on the command line end up as a list of escaped strings. | |
# Hence you can eval them to get the literal values properly entered into | |
# an expect command. | |
# | |
# ./expect_argv '---&;`'\''"|*?~<>^()[]{}$\---' | |
# ---&;`'"|*?~<>^()[]{}$\--- | |
# | |
eval spawn -noecho printf "%s\\n" $argv | |
expect eof |
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
#!/usr/bin/expect -f | |
############################################################################# | |
# Variables have values that have already been stored with expect (and hence | |
# do not need escaping). If you set the variable in the script yourself then | |
# obviously you need to tcl escaping, but if you inherit variables from the | |
# environment then the values will already be entered. | |
# | |
# export VAR='---&;`'\''"|*?~<>^()[]{}$\---' | |
# ./expect_env | |
# ---&;`'"|*?~<>^()[]{}$\--- | |
# | |
puts $env(VAR) |
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
#!/usr/bin/expect -f | |
############################################################################# | |
# As with the `expect_env` example, the strategy is to get the strings into | |
# variables thereby avoid having to escape special characters. Rather than | |
# using ENV, this uses a file to provide the values. | |
# | |
# printf "%s\n" '---&;`'\''"|*?~<>^()[]{}$\---' > file | |
# ./expect_file | |
# ---&;`'"|*?~<>^()[]{}$\--- | |
# | |
set input [open "file" "r"] | |
gets $input line | |
puts $line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment