i have to do a script that allows user to search for a file. I am total newbie in bash so you have to forgive me. I have problems with 3. Maximum file size, 4. Last modification date and 6. File content.
In option 3 Max file size, when i type anything program excludes any file,
In option 4 it gives me an error "Invalid argument for -mtime
and in
In option 6 it is "unknown expression -l
for -grep
Here is some of my code:
#!/bin/bash
OPTION=0
MAX_SIZE=""
LAST_MOD_DATA
CONTENT=""
SEARCH_CONTENT=""
while [ $OPTION -ne 8 ]
do
read OPTION
if [ $OPTION -eq 3 ]
then
echo "Enter max allowed file size:"
read MAX_SIZE
SEARCH_CONTENT = $SEARCH_CONTENT' -size '$MAX_SIZE
fi
if [ $OPTION -eq 4 ]
then
echo "Enter the last day the file was modified:"
read LAST_MOD_DAY
SEARCH_CONTENT = $SEARCH_CONTENT' -mtime '$LAST_MOD_DAY
fi
if [ $OPTION -eq 6 ]
then
echo "Enter the file content:"
read CONTENT
SEARCH_CONTENT = $SEARCH_CONTENT' -exec grep -l '$CONTENT $FILE_NAME
fi
if [ $OPTION -eq 7 ]
then
echo "Searched files:"
echo find $SEARCH_CONTENT
fi
done
echo "The end"