Linux 字符串形式的Shell脚本参数

Linux 字符串形式的Shell脚本参数,linux,string,shell,Linux,String,Shell,我有一个shell脚本,我将一些参数传递给它。在这个脚本中,我构建了一个简单的json字符串 以下是shell脚本A: firstname=${1} lastname={$2} email={$3} json='{"firstname":"'"$firstname"'","lastname":"'"$lastname"'","email":"'"$email"'"}' # do web request here shell脚本B会这样调用它: firstname="aa" lastname

我有一个shell脚本,我将一些参数传递给它。在这个脚本中,我构建了一个简单的json字符串

以下是shell脚本A:

firstname=${1}
lastname={$2}
email={$3}

json='{"firstname":"'"$firstname"'","lastname":"'"$lastname"'","email":"'"$email"'"}'

# do web request here
shell脚本B会这样调用它:

firstname="aa"
lastname="bb"
email="cc@cc.cc"
./scriptB.sh ${firstname} ${lastname} ${email}
在我将这个json发布到服务器之后,json中的所有值都封装在大括号中:{aa},{bb}{cc@cc.cc}. 在这种情况下,服务器不可能是问题所在


我认为这与不正确转义或错误使用字符串引号有关?

在您的第一个脚本中,
{
}
不一致且不带引号。尝试:

firstname="${1}"
lastname="${2}"
email="${3}"

谢谢,我回家后会调查一下,让你知道这是否有效。它是这样工作的:firstname=“${1}”lastname=“${2}”email=“${3}”所有这些都用花括号括起来了吗?如果您的示例代码是准确的,firstname不应该有大括号,但是lastname和email会有大括号。