bash - pattern matching in sudoers file using tab space in pattern -


i need write shell script check entry there or not in /etc/sudoers file

this pattern need check nimbus all=(all) nopasswd:all

in pattern word word tab space there

how find pattern exist in file /etc/sudoers or not using linux shell script root user

  somestring='nimbus      all=(all)       nopasswd:all' file=sudoers echo $file echo -e $somestring  if grep -q $somestring "$file";    echo "line found" else    echo "line not found" fi 

error got grep: all=(all): no such file or directory grep: nopasswd:all: no such file or directory

please me in regard

thanks sagar

the problem script is, not escaping(\) meta-characters(( , ) in case) grep identify them have special meaning.

also quoting variables prevents word splitting , glob expansion, , prevents script breaking when input contains spaces, line feeds, glob characters , such.

the modified version of script should like

#!/bin/bash  somestring='nimbus      all=\(all\)       nopasswd:all'      # notice '\' of characters file=sudoers echo "$file" echo -e "$somestring"  if grep -qe "$somestring" "$file";     echo "line found" else     echo "line not found" fi 

with change script works.

$ cat sudoers nimbus      all=(all)       nopasswd:all foo bar  foobar  $ ./script.sh sudoers nimbus      all=\(all\)       nopasswd:all line found 

read more grep-regular-expressions


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -