3

I am writing some script to make a directory, but I want firstly sure that the name that the user insert is correct. for this issue I wrote something like below (FILE.txt is the file which the user name saved in)

if grep -q '>' FILE.txt then echo "You should avoid inserting ">" in your code!" fi 

But it seems that the bash thought that I want to insert to output and so it give this error: -sh: syntax error near unexpected token `newline' Do anybody have some idea? tnx for help

1
  • I've always liked referring folks to this answer when there's a problem with quoting. :-) Commented Oct 21, 2015 at 22:37

2 Answers 2

5

The problem isn't with your grep line, it's with your echo line. Your shell sees it as:

echo "You should avoid inserting " > " in your code!" 

You can fix this simply by removing the quotes in the middle of the sentence, or using single quotes like:

echo "You should avoid inserting '>' in your code!" 
Sign up to request clarification or add additional context in comments.

1 Comment

I think that OP wants to save "" around > like this: echo You should avoid inserting '">"' in your code!
1

You have to escape the quote in your echo statement:

if grep -q '>' file.txt; then echo "You should avoid inserting \">\" in your code!" else echo "code is good" fi 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.