Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

bash - grep for expression containing variable

I want to add this command grep -co '5' $INFILE in a bash script. The problem is that instead of 5 i want to use a variable in its place so i write:

V=`grep -co '$L' $INFILE`

but it does not work since the $ is used to describe internally the end of line in grep. How can i make it work? Is there an escape sequence for $ to make it use its bash meaning of the value of a variable?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use " instead of ' to allow expansion of your $L variable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...