How to split a variable in two arguments with exec in TCL?

I want to create a simple console in Tcl / Tk

I have two problems. First we change each * with [glob *], but also, when my record contains "ls -a", she does not understand that ls is a command and the -afirst arg.

How can i do this?

thank

proc execute {} {
    # ajoute le contenu de .add_frame.add_entry
    set value [.add_frame.add_entry get]
    if {[string compare "$value" ""] == 1} {
    .text insert end "\n\n% $value\n"
        .text insert end [exec $value]
    .add_frame.add_entry delete 0 end
    }
}

frame .add_frame

label .add_frame.add_label -text "Nouvel élément : "
entry .add_frame.add_entry
button .add_frame.add_button -text "Executer" -command execute
button .add_frame.exit_button -text "Quitter" -command exit

bind  .add_frame.add_entry  <Return> execute
bind  .add_frame.add_entry  <KP_Enter> execute
bind  .  <Escape> exit
bind  .  <Control-q> exit

pack .add_frame.add_label -side left
pack .add_frame.exit_button -side right
pack .add_frame.add_button -side right
pack .add_frame.add_entry -fill x -expand true

pack .add_frame -side top -fill x

text .text
.text insert end  "% Tcl/Tk Console"

pack .text -side bottom -fill both -expand true
+3
source share
1 answer

The simple answer in Tcl 8.5 is to use this:

exec {*}$value

In 8.4 and earlier this syntax did not exist. This meant that many people wrote this:

eval exec $value

But the actually safe version was one of the following:

eval exec [lrange $value 0 end]
eval [linsert $value 0 exec]

, $value , , :

exec /usr/bin/bash -c $value
+7

Source: https://habr.com/ru/post/1764688/


All Articles