Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created November 10, 2012 16:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkerbot/4051679 to your computer and use it in GitHub Desktop.
Save thinkerbot/4051679 to your computer and use it in GitHub Desktop.
Expect - special characters without escape
#!/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
#!/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)
#!/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