Posted to tcl by berndj at Thu Jul 04 15:42:19 GMT 2019view raw

  1. #!/usr/bin/tclsh
  2.  
  3. proc libfunc_args { filename } {
  4. set r { }
  5. foreach i [split $filename "/"] {
  6. lappend r $i
  7. }
  8. return $r
  9. }
  10.  
  11. proc vectors { dummy tool_options } {
  12. set input_file "/etc/hosts"
  13. set command { }
  14. foreach opt $tool_options {
  15. set x [expr "\"$opt\""]
  16. lappend command $x
  17. puts "opt: $opt -> $x"
  18. }
  19.  
  20. return $command
  21. }
  22.  
  23. set cmd [vectors "dummy" { "hello" "world" "a sentence" "[libfunc_args \$input_file]" }]
  24. foreach c $cmd {
  25. puts "command item: $c"
  26. }
  27.  
  28.  
  29. Actual output:
  30.  
  31. opt: hello -> hello
  32. opt: world -> world
  33. opt: a sentence -> a sentence
  34. opt: [libfunc_args $input_file] -> {} etc hosts
  35. command item: hello
  36. command item: world
  37. command item: a sentence
  38. command item: {} etc hosts
  39.  
  40. Desired output:
  41.  
  42. opt: hello -> hello
  43. opt: world -> world
  44. opt: a sentence -> a sentence
  45. opt: [libfunc_args $input_file] -> {} etc hosts
  46. command item: hello
  47. command item: world
  48. command item: a sentence
  49. command item: {}
  50. command item: etc
  51. command item: hosts