I'm surprised that:
$ if [ -n "$(findmnt | grep "\""proc"\"" | head -n 1)" ]; then echo 1; else echo 2; fi
2
I've used "\""
before IIRC after reading https://unix.stackexchange.com/a/187452/446998, after all it works:
$ echo "1"\""2"\""3"
1"2"3
Why it doesn't in a first case?
Revisiting How to escape quotes in shell? and trying to follow accepted answer resulted in opposite issue: finding non-existing mounts:
$ if [ -n $'$(findmnt | grep "\proc111"\ | head -n 1)' ]; then echo 1; else echo 2; fi
1
It works w/out quotes for grep inside:
~$ if [ -n "$(findmnt | grep proc111 | head -n 1)" ]; then echo 1; else echo 2; fi
2
~$ if [ -n "$(findmnt | grep proc | head -n 1)" ]; then echo 1; else echo 2; fi
1
I've tried to read suggested Escaping double quotes inside command substitution but could not immediately apply to my code.
grep
is not searching for literal double quotes in the pattern, which does not exist in the default output offindmnt
. – Snake Dec 23 '21 at 02:35