Why do I double quote the array in shell?

Why do I double quote the array in shell?

Double quote to prevent globbing and word splitting. I’m not worried about word splitting in this case, but in a lot of other cases I am, so I’m trying to keep my code consistent. However, when I double quote the array, the command fails.

Is there a problem with quoting an array expansion?

There is absolutely no problem with quoting an array expansion. And, of course, there is no problem with no quoting it either as long as you know and accept the consequences. Any non-quoted expansion is subject to splitting and globbing.

How to pass a string array as a parameter in a PowerShell 4.0?

I am working with PowerShell 4.0 and I am trying to pass a string array as one of the parameters for an Invoke-Command -ScriptBlock in which I am calling another PowerShell script on a remote server. When I do this, the string array seems to get flattened so that it appears as a single string value, rather than a string array.

What happens when you do not quote a value in shell?

So when you echo the quoted value, the newline is preserved. when you do not quote it, the shell consumes it as intertoken whitespace to ignore. This is also why sha256sum is failing. If you have a file called foo, readarray is passing a value of foo , which does not correspond to a file.

What’s the difference between double quoting and Word splitting?

So, the actual string in the array is file1 [newline]. Without quotes, word splitting removes trailing whitespace, fixing the newline. But if you had filenames with spaces in them, word splitting would mess them up, as usual. Double quoting the array prevents that.

Can a string have both single and double quotes?

Strings don’t inherently have either single or double quotes associated with them. So, it doesn’t matter if your browser displays it as [‘a’,’b’,’c’] or [“a”,”b”,”c\\. The array still contains the same thing. What you DO care about is how it is converted into a string, as you stated in your question.