Matching 'whole text only' using expect -


i trying match string in expect programming mentioned below

send "cd $tftproot/cmbuild\r" expect \\$ send "ls -lrt\r"  expect -ex "10.0.1.10000-2" {       send "touch $builddir\r"       expect \\$   } 

in specified directory there file name 10.0.1.10000-24. expect command expect -ex "10.0.1.10000-2" matching file 10.0.1.10000-24 , getting passed.

i have tried expect -exact "10.0.1.10000-2" , expect "10.0.1.10000-2", both commands getting passed.

i want match exact string(10.0.1.10000-2) passing.

there can many ways. assume file 1 listed @ last in directory follows,

/var/root # ls -lrt                                                              total 4                                                                          -rw-r--r--    1 root     root           242 nov 12 10:08 hello.c                 lrwxrwxrwx    1 root     root             9 nov 12 10:08 dos -> /root/dos                   -rw-r--r--    1 root     root             0 nov 12 10:08 10.0.1.10000-24 -rw-r--r--    1 root     root             0 nov 12 10:08 10.0.10000-2         /var/root #  

then can use pattern

expect  "10.0.1.10000-2$" {       send "touch $builddir\r"       expect \\$   } 

if file can in between entries, matching newline \n

expect "10.0.1.10000-2\n" {       send "touch $builddir\r"       expect \\$   }  

or matching white-space character \s

expect "10.0.1.10000-2\s+" {           send "touch $builddir\r"           expect \\$       } 

can used based on requirement.

to avoid confusion, have use ls 10.0.1.10000-2 directly, better , can output, if matching name.

update :

there 1 more easy way available. can make use of word boundaries ( \m , \m ).

expect "10.0.1.10000-2\m" {               send "touch $builddir\r"               expect \\$           } 

\m matches @ start of word. is, matches @ position has non-word character left of it, , word character right of it. matches @ start of string if first character in string word character. \m matches @ end of word. matches @ position has word character left of it, , non-word character right of it. matches @ end of string if last character in string word character.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -