简体   繁体   English

如何grep带有撇号的文本文件?

[英]How to grep a file for text with apostrophes?

people... Im coding a linux bash file and I need it to grep for the text 'Josh''1234 .人们...我正在编写一个 linux bash 文件,我需要它来 grep 文本'Josh''1234 Is there any way to ignore those apostrophes?有没有办法忽略这些撇号? heres what I tried: (Josh is set as usr and 1234 as pas .)这是我尝试过的:(Josh 设置为usr , 1234 设置为pas 。)

if grep -q '\'$usr\'\'$pas\''; then
    echo username and password correct
else
    echo INCORECT
    sleep 10
fi

Just quote with double quotes, so that single quotes can be included normally:只需用双引号引用,这样就可以正常包含单引号:

grep "'$usr''$pas"
#    ^           ^
#     ^    ^^
#     single quotes to match

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM