White space

The fact that [[ is not a command is significant where white space is concerned. As a keyword, [[ parses its arguments before bash expands them. As such, a single parameter will always be represented as a single argument. Even though it goes against best practice, [[ can alleviate some of the issues associated with white space within parameter values. Reconsidering the condition we tested earlier, we can omit the quotes when using [[, as shown in the following example:

$ echo "The File Contents">"my file"$ FILE="my file"$ [[ -f $FILE && -r $FILE ]] && cat "$FILE"

We still need to quote the parameter when using cat, as you can see, and we can use quotes within the double brackets but they become optional. Note that we can also ...

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.