I have a list of .gz files,like:
abc-1.1.0-abc.tar.gz
abc-1.2.3-hfc.tar.gz
hfg-1.8.9-jdh.tar.gz
Content of file_name:
abcd_name_fb
hsgdh_name_cd
in my scipt, i'm capturing the strings '1.1.0,1.2.3,1.8.9' from the file names and i need to pass these strings as a 3rd argument/parameter.
Basically, my script looks like this:
if [[ "$#" -ne '3' ]]
then
exit 1
fi
for i in /home/dir/*.gz
do
n=$( echo $i |sed -E -n 's/.*\-(.*)\-.*/\1/p')
echo $n
done > /home/dir/n.txt
while read -r name
do
if [[ "$1" == "some_string" ]] && [[ "$name" == "$2" ]] || [[ "$2" == "ALL" ]]
then
mkdir -p /home/ce/pwde/${name}
fi
done < /home/file_name
I'm unable to figure out how to read the file n.txt for validating the 3rd parameter and at the same time reading the file file_name.
I'm executing my script from the terminal as:
./script.sh some_string ALL 1.2.3
Thanks.
file_name."$1"have? It is not clear from your question. You also might want to show how you call your script and which error is spit.n.txtto read the 3rd parameter and then the filefile_name.Ato read thelineto performopsfunction.n.txtline by line and check if$3equals one of them? Also, the nested loop from your previous comment might be a way. Have you tried it? It may be worth adding your attempt to the code you posted.