shell script “${array[@]}” expansion: first and last entry have extra characters [closed]

余生颓废 提交于 2019-12-13 19:59:35

问题


I have a shell script that uses an array. The script cycle through the entries of the array but for some reason the first and last entry has a problem.

The array:

Queue_Names=( CLQueue DLQ ExpiryQueue )

The for Loop:

for i in “${Queue_Names[@]}”
do
     #do stuff
done 

I can see in the console and shows that for the first entry it shows: �CLQueue. The last entry shows: ExpiryQueue�

I'm guessing these are markers to know the start and end of the array. Unfortunately it is interfering with the functionality of the script. I use these Queue names to search for something and it fails to find it because of the added character. How do I get rid of them or is there a code change I do to avoid the problem?


回答1:


“${Queue_Names[@]}” is not "${Queue_Names[@]}", because “” is not "".

"Smart quotes" aren't recognized as quotes at all in bash; thus, the effect is the same as if the expansion had been unquoted -- string-splitting and glob-expansion on array contents -- with the literal "quotes" grafted around the start and end characters.

You need to use real quotes -- "" -- not opening/closing "smart quotes" created by some word processing software or corporate email tools.



来源:https://stackoverflow.com/questions/29548455/shell-script-array-expansion-first-and-last-entry-have-extra-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!