#!/bin/bash
echo "Enter the search string"
read str
for i in `ls -ltr | grep $str > filter123.txt ; awk '{ print $9 }' filter123.txt` ; do
if [ $i != "username_list.txt" || $i != "user_list.txt" ] ; then
else
rm $i
fi
done
I'm a beginner of unix shell scritping, i create above file for delete file based on given string using grep method. while i executing above script file it showing error like "./rm_file.txt: line 10: syntax error near unexpected token `else' ". please suggested what's the error in this script.
grepandawkand a temporary file? Just dols -ltr | awk "/$str/{print \$9}"(This will fail if str contains certain characters, but so doesgrep $str)[[]](see mywiki.wooledge.org/BashPitfalls#A.5B_.24foo_.3D_.22bar.22_.5D). Also not sure why you're tryingif !a || !b then nothing else somethinginstead of the logically equivalentif a && b then something.