Wednesday, 15 July 2015

linux - Number of arguments requirement input validation -


Write a script to search for a file for the pattern and the number of lines and the number of lines that accompany that file Output / P>

I have a script

  #! / Bin / bash echo "------ file =" $ 2 "------" grep -ne $ 1 $ 2 "  

It works just fine, But now I need verification, I have to write all what I want

  if [[number of arguments & lt; 2]]; Then repeat "Enter two arguments" and repeat   

and anything that is

  if [[$ 2 / file / directory is not]] ;  

Itemprop = "text">

For Question 1: / H3>
  If [[number of arguments & lt; 2]]; Then, "two arguments should be entered", echoing   

You can do this:

  If [[$ # -ne 2]] then Use "echo": Enter Question 2:  
  for two arguments "exit -1fi   

if [[$ 2 files / directory] Do not have]]; then "need a second filing" />>

You can do this:

  If [[! -a $ 2]] then "file does not exist!" Exit -2 fi    

No comments:

Post a Comment