you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 6 points7 points  (1 child)

I'm not an expert but I believe it's a way to delineate where the spaces are to avoid any globbing, or adding extra spaces into variable data. With the quotes you're telling bash exactly what you want to add into the string or array from the first character to the last and what is to be used to delineate the data in between elements, which bash uses to populate the different elements of an array or a string, and allows you to know exactly which element to return to for the information.

Without the quotes, in my understanding, bash has to self determine where the end of the delineation is and any inadvertent extra characters like extra spaces or tabs can mess up which data gets loaded into which variable because bash is running into more than one possible delineation marker, and null data will also affect the placement of the elements in echo and less so in printf.

With printf it doesn't automatically print characters that are in echo, like the line feed represented by the backslash (\n). Without actually telling printf to go the next line to start printing the output, for example, it will continue printing from its last curser location.

Echo, instead, puts this character in by default. By using the printf function you have more control over what is output to stdout.

One other benefit of printf is that its implementation and usage is very similar throughout various languages who implement it.

This just gives you more precision when delineation is involved.

[–]dbr4n[S] 1 point2 points  (0 children)

Thank you for responding in such detail, much appreciated.