如何验证expect shell脚本中输入参数的数量?
我正在尝试验证正在创建的shell脚本中的参数数量。如何验证expect shell脚本中输入参数的数量?,shell,unix,expect,Shell,Unix,Expect,我正在尝试验证正在创建的shell脚本中的参数数量。 脚本将使用expect 错误 invalid command name "$#" while executing "$# -ne 3 " invoked from within "if [ $# -ne 3 ] then" 脚本: #!/usr/bin/expect -f if [ $# -ne 3 ] then echo "Wrong number of arguments provided" echo "fg
脚本将使用expect 错误
invalid command name "$#"
while executing
"$# -ne 3 "
invoked from within
"if [ $# -ne 3 ] then"
脚本:
#!/usr/bin/expect -f
if [ $# -ne 3 ] then
echo "Wrong number of arguments provided"
echo "fgrep_host.sh hostname filter_text new_file"
exit
fi
正如@Dinesh所说,一个
expect
脚本不是一个shell脚本,而是一个expect
脚本,它是Tcl
要想做你想做的事,你可以写:
#!/usr/bin/expect -f
if {$argc != 3} {
puts "Wrong number of arguments provided"
puts "fgrep_host.sh hostname filter_text new_file"
exit 1
}
(尽管您不应该添加.sh
扩展名)
您必须阅读
expect
和Tcl
才能继续。正如@Dinesh所说,expect
脚本不是一个shell脚本,而是一个expect
脚本,即Tcl
要想做你想做的事,你可以写:
#!/usr/bin/expect -f
if {$argc != 3} {
puts "Wrong number of arguments provided"
puts "fgrep_host.sh hostname filter_text new_file"
exit 1
}
(尽管您不应该添加.sh
扩展名)
您必须阅读
expect
和Tcl
才能继续。编写纯expect
脚本时,不应使用bash命令。编写纯expect
脚本时,不应使用bash命令。谢谢!!第一次写expect脚本。谢谢!!第一次编写expect脚本。