- 论坛徽章:
- 0
|
本帖最后由 zhangshebao 于 2010-05-06 13:20 编辑
最近在写expect脚本,用来管理网络设备。
网上索了一下,有一些脚本。系统介络expect的很少,也很浅。
expect1.3> string match
wrong # args: should be "string match ?-nocase? pattern string"
while executing
"string match "
expect1.4> string match "*abc" "jkjkjabc"
1
expect1.5> string match "jkjkj{cba}" jkjkjabc
0
expect1.6> string match "jkjkj{abc}" jkjkjabc
0
expect1.7> string match "{a-z}" "b"
0
expect1.8> string match "[a-z]" "b"
invalid command name "a-z"
while executing
"a-z"
expect1.9> string match "{abc}" "b"
0
expect1.10> string match "\[a-z\]" "b"
1
expect1.11> string match "\[a-z\]+" "b"
0
expect1.12> string match "\[a-z\]\+" "b"
0
expect1.13> string match "\[a-z\]" "bcd"
0
expect1.14> string match "\[a-z\]{3}" "bcd"
0
expect1.15> string match "\[a-z\]\{3\}" "bcd"
0
现在确定string match "规则表达式" "串"
规则表达式中*表示任意字符串,\[a-z\]匹配1个字母。
谁知道expect中的expect及string match使用的规则表达式更详细的用法?
expect1.16> set a "abc 123"
abc 123
expect1.17> if [ string match "*3" $a ] { puts "OK" }
OK
expect1.18> if [ string match "\[a-z0-9\]\[a-z0-9\]\[a-z0-9\] \[a-z0-9\]\[a-z0-9\]\[a-z0-9\]" $a ] {puts "ok" }
ok
expect1.19>
bash-3.2$ expect
expect1.1> ?
ambiguous command name "?": after append array auto_execok auto_import auto_load auto_load_index auto_qualify binary break case catch cd clock close concat
continue debug disconnect encoding eof error eval exec exit exp_close exp_continue exp_debug exp_disconnect exp_exit exp_fork exp_getpid exp_inter_return ex
p_interact exp_internal exp_interpreter exp_log_file exp_log_user exp_match_max exp_open exp_overlay exp_parity exp_pid exp_remove_nulls exp_send exp_send_e
rror exp_send_log exp_send_tty exp_send_user exp_sleep exp_spawn exp_strace exp_stty exp_system exp_timestamp exp_trap exp_version exp_wait expect expect_af
ter expect_background expect_before expect_tty expect_user expect_version expr fblocked fconfigure fcopy file fileevent flush for foreach fork format getpid
gets glob global history if incr info inter_return interact interp interpreter join lappend lindex linsert list llength load log_file log_user lrange lrepl
ace lsearch lset lsort match_max namespace open overlay package parity pid proc prompt1 prompt2 puts pwd read regexp regsub remove_nulls rename return scan
seek send send_error send_log send_tty send_user set sleep socket source spawn split strace string stty subst switch system tclLog tell time timestamp trace
trap unknown unset update uplevel upvar variable vwait wait while
while executing
"?"
expect1.2> string ?
bad option "?": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, tri
mleft, trimright, wordend, or wordstart
while executing
"string ?"
expect1.3> string match
wrong # args: should be "string match ?-nocase? pattern string"
while executing
"string match " |
|