I'm facing a problem while trying to pass a variable value to a grep command.
In essence, I want to grep out the lines which match my pattern and the pattern is stored in a variable. I take in the input from the user, and parse through myfile and see if the pattern exists(no problem here).
If it exists I want to display the lines which have the pattern i.e grep it out.
My code:
if {$a==1} {
puts "serial number exists"
exec grep $sn myfile } else {
puts "serial number does not exist"}
My input: SN02
My result when I run grep in Shell terminal( grep "SN02" myfile):
serial number exists
SN02 xyz rtw 345
SN02 gfs rew 786
My result when I try to execute grep in Tcl script:
serial number exists
The lines which match the pattern are not displayed.
exec. Also, put the} else {on its own line. My TCL is a bit rusty, so I'm not sure if either is the real issue ;-)elseon the same line as the closing braces is it threw an error while executing the script. Apparently you need to includeelsein the same line where theifhas its closing brace.} else {-fragment (braces and else-keyword) on its own line.