Mario Jost
Mario Jost

Reputation: 284

TCL lrange command creating arrays for things in quotes

I have following simplified code:

set getevent [exec "show running-config | section UPDATESCRIPTS"]
set geteventsplit [split $getevent "\n"]
foreach entry $geteventsplit {
    if {[llength $entry] > 1} {
        lappend finalconfig1 [lrange $entry 0 end]
        lappend finalconfig2 $entry
    }
}
puts "Output1:"
puts $finalconfig1
puts "Output2:"
puts $finalconfig2

So the data that i get back from the first line looks like this:

event manager applet UPDATESCRIPTS
 event timer cron cron-entry "30 1 * * *"
 action 001 cli command "enable"
 action 002 cli command "set updatescripts"

The output of the running script looks like this:

Output1:
{event manager applet UPDATESCRIPTS} {event timer cron cron-entry {30 1 * * *}} {action 001 cli command enable} {action 002 cli command {set updatescripts}}
Output2:
{event manager applet UPDATESCRIPTS
} { event timer cron cron-entry "30 1 * * *"
} { action 001 cli command "enable"
} { action 002 cli command "set updatescripts"
}

Now the problem that i have is that i want to retain the quotation marks. So the output1 takes originally this line:

event timer cron cron-entry "30 1 * * *"

and converts it to this:

event timer cron cron-entry {30 1 * * *}

Question: how can i retain the quotation marks in the lrange command?

Upvotes: 1

Views: 72

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137757

Are you keeping the text of the line or a list of the words in the line? They're different things! The lrange command does not retain the one-word parts; you use it when you're interested in the list of words in the line only.

Also, you are totally relying on the output from that subprocess having the same interpretation of word as Tcl. That's not generally recommended even if you can get away with it. There are other ways of getting "the list of words in a record" that may be better for your use cases.

Upvotes: 0

Related Questions