Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 2
    I still don't get what is the difference between single and double quotes. In the example you posted, they seem to do the same thing. Commented Sep 29, 2013 at 22:11
  • What if I have a grep regex that should match a single quote or a double quote, how can I write it with grep? grep '["]\'" doesn't seem work... Commented Sep 17, 2015 at 13:13
  • single and double quotes do the same thing for our purposes. To match a quote just use " or '. If surrounding the pattern in quotes, use the different quote to the one you want to match, e.g. matching " within a pattern would be 'foo"bar' Commented Jan 15, 2016 at 2:18
  • 1
    For both types of quotes inside pattern, use single quotes around outer command and escape with \' see unix.stackexchange.com/questions/23347/… Commented Jan 15, 2016 at 2:24
  • In this specific case echo is sufficient to show what the shell is doing, but very, very often it is not (and for someone to know a priori if echo would be sufficient, they would need to understand shell parsing enough to not need to ask the question at all). For example, one can't use echo to tell the difference between echo "hello world" and echo "hello" "world". It's a better habit to teach people to use set -x, or even printcmd() { printf '%q ' "$@"; echo; } and then printcmd grep -e show\( test.txt. (In bash 5, printcmd() { echo "${@@Q}"; } is a shorter alternative). Commented May 8, 2022 at 16:37