Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux Get-expect接受一个包含空格的变量_Linux_Shell - Fatal编程技术网

Linux Get-expect接受一个包含空格的变量

Linux Get-expect接受一个包含空格的变量,linux,shell,Linux,Shell,在我的expect脚本中,我想添加两个变量。它们都将成为脚本中的变量 hello="My Life" world="is wonderful" ./script.sh $hello $world 在script.sh中 #!/usr/bin/expect set timeout 10 match_max 100000000 set first_var [lindex $argv 0] set second_var [lindex $argv 1] 目前, first_var="M

在我的expect脚本中,我想添加两个变量。它们都将成为脚本中的变量

 hello="My Life" 
 world="is wonderful" 
 ./script.sh $hello $world
在script.sh中

#!/usr/bin/expect
set timeout 10
match_max 100000000

set first_var [lindex $argv 0]
set second_var [lindex $argv 1]
目前,

first_var="My"
second_var="Life"
下面的代码在不作为变量传入时按预期工作

./script.sh 'My Life' 'is wonderful'

我需要知道如何让脚本接收变量,并且仍然忽略其中的空白。

您还必须在引号中传递变量

./script.sh“$hello”“$world”

按照Bash扩展的工作方式,这些变量将在脚本运行之前展开。这将与命令的运行方式相同

/剧本“我的生活”很精彩


参数周围的引号指示shell不要通过字段分隔符拆分。

您还必须在引号内传递变量

./script.sh“$hello”“$world”

按照Bash扩展的工作方式,这些变量将在脚本运行之前展开。这将与命令的运行方式相同

/剧本“我的生活”很精彩

参数周围的引号指示shell不要通过字段分隔符拆分。

使用
/script.sh“$hello”“$world”
是我们用于此的最佳副本吗?这有点间接。使用
/script.sh“$hello”“$world”
是我们最好的复制品吗?这有点间接。