Recently, I am busy coding the bash script to feed my needs. However, during the coding time, I found the usage of double quotes is contradicted with each other at some times. For example, I try to find some files that matched the regex, such as ls "*.log"
. I habitually wrap the *.log
with double quotes but get the error cannot access '*.txt': No such file or directory
.
After that, I found the reason from a tutorial that it is useless to put the *
in double-quotes when you want the *
acts as a wildcard. Therefore, ls *.log
is the correct usage.
However, when I use the grep
command with regex, all three of them (""
,''
,non-quote) do not change the original meaning of my regex, such as grep "^s.txt"
. At this time, double-quotes make the regex active.
Is there exist some design conflicts between the commands? And could you please give me some tricks to quickly grasp the correct usage of quotes for usual commands?
Is there exist some design conflicts between the commands?
" yes, of course; these are completely two different commands and having different functionalities. seeman grep
andman ls
for more info. – αғsнιη Jul 03 '20 at 03:38bash
use globbing to represent multiple filenames using special characters called wildcards with a single filename. A wildcard is essentially a symbol which may be used to substitute for one or more characters.bash
also supports extended globbing; The options extglob and globstar must be set to get the extended functionality, i.e.shopt -s globstar
. – fpmurphy Jul 03 '20 at 03:47grep
andls
are all builtin bash commands at the very beginning, so they shouldn't conflict the rule of bash that how to handle and parse the double-quotes. However, now I found grep is not the builtin command. – Simon Hu Jul 04 '20 at 11:40