0

I have a file with a list of names. for each name I want to find a file that starts with that name and ends with a certain suffix. I wrote a short bash script but am not getting any output from the find command

#!/bin/bash
file="/my_folder/list_of_names"
while read var
do
    echo $var
    find /folder/of/files/ -name "${var}*" -and -name *.bam
done <"$file"

The list of names gets printed to the screen correctly thanks to the echo command. If I set "var" manually to equal one of the names from the list and run the find command with the parameters it returns the file I'm looking for but within the script it doesn't work.

Amos
  • 107
  • 1
  • 3
  • 11
  • 1
    What is the output of `echo "=$var="`? It sounds like you have hidden characters (most likely DOS line endings) that make `"$var*"` not be the pattern you think it is. – chepner Sep 27 '18 at 12:48
  • Thank you. I was thinking I might have a problem with my script and even tried dos2unix on the script but now I tried to run dos2unix on the file with the list names and now the script is working – Amos Sep 27 '18 at 12:57

0 Answers0