'Shell script when we need to quote or unquote [duplicate]
I am trying to understand in what situation we should use quote the command while parsing the output from it or when should not.
Case 1:
I am using below command into my bash script which works well while using like below which results the correct output.
$ ssh -i /home/apache.ssh/sshKey root@dbhost01 -o StrictHostKeyChecking=no -o PasswordAuthentication=no cat /etc/redhat-release| awk 'END{print $7}'
6.7
Case 2:
While wrapping like "cat /etc/redhat-release| awk 'END{print $7}'"
which results the complete file output and skips parsing though.
$ ssh -i /home/apache.ssh/sshKey root@dbhost01 -o StrictHostKeyChecking=no -o PasswordAuthentication=no "cat /etc/redhat-release| awk 'END{print $7}'"
Red Hat Enterprise Linux Server release 6.7 (Santiago)
Please advise what could be the right approach while using this into bash scripts.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|