I am making a simple shell script which will minimize the time I spend in searching all directories under a parent directory and grep some things inside some files. Here's my script.#!/bin/shMainDir=/var/opt/database/1227-1239/cd $MainDirfor dir in $(ls); dogrep -i STAGE,te_start_seq Starting $dir/his_file | tail -1 >> /home/xtee/sst-logs.outif [ -f $dir/sysconfig.out];then    grep -A 1 Drive Model $dir/sysconfig.out | tail -1 >> /home/xtee/sst-logs.outelse    grep -m 1 Physical memory size $dir/node0/setupsys.out | tail -1 >> /home/xtee/sst-logs.outfidoneThe script is supposed to grep the string STAGE,te_start_seq Starting under the file his_file then dump it sst-logs.out which it does. My problem though is the part in the if statement. The script should check the current directory for sysconfig.out, grep drive model and dump it to sst-logs.out if it exists, otherwise, change directory to node0 then grep physical memory size from setupsys.out and dump it to sst-logs.out. My problem is, it seems the if then else statement seems not to work as it doesn`t dump any data at all but if i execute grep manually, i do have data.What is wrong with my shell script? Is there any more efficient way in doing this?
Shell script to recursively grep data from certain files in the directory and return values to file
shell;shell script;scripting
if [ -r $dir/sysconfig.out ];Notice the whitespace between t and ].