When we learn the inner works of a shell, we quickly realise the benefit of using double quotes with request for variable substitution.
For example, to assign a value to a variable (and preserve leading spaces), we would use:
$ address=" 23 Acacia Avenue "
A correct quotation is needed to recall the value complete with the spaces:
The less known application of the quotes is when they are around the command substitution syntax. By default, POSIX shells remove trailing new-lines during command substitution. Double quotes change this behaviour!
Compare the output of the following commands:
$ echo $(ls)
log.1 log.2 log.3
and
$ echo "$(ls)"
log.1
log.2
log.3
No comments:
Post a Comment