将参数从Tcl脚本传递给cygwin bash

时间:2017-12-19 12:43:48

标签: bash shell tcl

我需要从tcl脚本调用cygwin bash并在bash打开后执行一些参数。 这是我的代码:

set gitBash ""

append gitBash "C:/cygwin/bin"

cd $gitBash

set command exec

lappend command "bash.exe"

lappend command "-c"

lappend command "cd cygdrive/c/workset"

问题是我收到此错误

couldn't execute "exec bash.exe -c {cd cygdrive\c\workset\CASTLE5\2_Castle5_Dev\1_Castle}": no such file or directory
    while executing
"exec $command"

任何提示?

1 个答案:

答案 0 :(得分:2)

exec不接受所有参数作为单个字符串。构造shell命令最安全的方法是使用list

% set command [list bash -c "cd /some/dir"]
bash -c {cd /some/dir}
% eval exec $command
bash: line 0: cd: /some/dir: No such file or directory
% exec {*}$command
bash: line 0: cd: /some/dir: No such file or directory
%

请注意,{*}语法需要Tcl 8.5。