写一个shell去处理mysql的数据,遇到一个拼接条件的问题。就是在-e中的sql语句中加where条件,模拟下。
lala=hehe
echo "'$lala'"
输出:'hehe'
这样就可以把参数拼接到where条件中
echo "select a from table where a='$lala' "
输出:select a from table where a='hehe'
这里注意下这种情况的输出
echo "select a from table where a="'$lala'" "
输出:select a from table where a=$lala
执行效果和下面这种方式一样
echo select a from t '$lala'
输出:select a from table where a=$lala
结论:外层“” 可以使内层‘’失效,变为单引号在字符串输出,若外层双引号再加双引号,则双引号使内层双引号失效,此时剩余的单引号生效。