regex - Checking a string to see if it contains numeric character in UNIX -


I'm new to Unix, only started it today at work, but have experienced it with Java, and the following The code is:

  # / bin / bash echo "Please enter a word:" grep -i $ word $ 1 Read the word. Cut-D ',' -f1,2 | Tr "," "-" & gt; Output  

This works fine, but now what I have to do, when the word is read, it is to check, there is nothing except letters and if the print has numeric characters "Invalid input!" Ask for the message and to re-enter them I had used regular expressions with a statement that it would be an easy way to do this, but not my head about how to use them for the use of Java applications around them. Can get it. Looking at all the solutions with regular expression in Linux, I could not find any help, because any help would be greatly appreciated, I could only find out if it was all numeric or not.

Another approach still exits from Grep 0 if a match , You can test the executable code:

  echo "$ {word}". Grep -q '[0- 9]' If [$? = 0]; Then resize the 'invalid input' file  

this is / bin / sh compatible.


Including the suggestions of Daenyth and John, it becomes

  if "$ {word}" is echoed. Grep '[0-9]' & gt; / Dev / null; Then echo 'invalid input' file  

Comments