使用含有空格作为一个参数变量 [英] Using a variable containing spaces as a single argument

查看:83
本文介绍了使用含有空格作为一个参数变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你觉得你有一个包含有空格其间的文本字符串变量,你要使用作为另一个脚本的输入参数。你会如何​​去传递变量的内容,而不必担心空间字符?

以下不工作:

  VAR1 =你好\\世界
#...做别的事情
./a_script.sh $ VAR1


解决方案

使用双引号:

  VAR1 =你好\\世界
#...做别的事情
./a_script.sh$ VAR1

Think you have a variable that contains a string of text with spaces inbetween and you want to use that as input arguments for another script. How would you go about passing the variable content without worrying about the space chars?

The following doesn't work:

VAR1=hello\ world
#... do something else
./a_script.sh $VAR1

解决方案

Use double quotes:

VAR1=hello\ world
#... do something else
./a_script.sh "$VAR1"

这篇关于使用含有空格作为一个参数变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆