#!/bin/bash while IFS='' read -r line || [[ -n "$line" ]]; do cd /home/Sud/Minimal\ Packages/All/ if [ -d $line ] then cp $line*.rpm /home/Sud/NewFolder/rpms/ else echo $line>>/home/Sud/NewFolder/notfound.txt fi done < "$1"
I am trying to run the above code to
- Read a text file line by line
- Search a folder if there is a directory by that name
- a) if yes; copy contents of that directory to another directory
- b) if not, copy the directory name to another text file.
Each time I run the script, it copies all names to
notfound.txt even though they are present in the folder I'm searching.
Where am I going wrong?