如何在Expect Shell中使用变量目录名称

邪恶熊猫

我想调用一个变量以在Expect Shell脚本中找到当前用户ID:

#!/usr/bin/expect -f 
set pass "password"
set username [id -un]
spawn scp -r root@serveraddress:/var/scpserver /Users/$username/Library/Songs/song.mp3`

不幸的是,这不起作用,因为它给了我以下错误

Mac:TestDir Matthew$ ./tester.sh 
invalid command name "id"
while executing "id -un"
invoked from within
"set username [id -un]"
(file "./tester.sh" line 3)`

其背后的想法是,无论将用户名分配给该计算机的用户名如何,我都可以在任何计算机上运行该脚本。

迪内什(Dinesh)

id -un是系统命令,而不是Tcl命令。您应该使用它exec来执行任何系统命令。

set username [exec id -un]

代替这种方式,您可以依靠Tcl的内置tcl_platform(user)变量来获取当前的用户名。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章