zoit
zoit

Reputation: 667

Error naming file with content of variable

I'm trying to name a file with the content of one variable doing this script

#!/bin/bash
IFS=$'\n'
file=mails.txt
lines=$(cat ${file})

for line in ${lines}; do
   echo "'${line}'"
   final=echo "'$line'" |sed -e 's/^\.\*\(.*\)\*\./\1/'
   curl -XGET "https://google.es" > $final.'.txt'
   sleep 2
 done

 IFS=""
 exit ${?}

The content of mails.txt is something like:

 .*john*.
 .*peter*.

And when I do that I have the error ./testcur.sh line 7: .john*. :order not found, the same with peter. How can I do to name the files john.txt and peter.txt

Upvotes: 0

Views: 30

Answers (1)

Yuji
Yuji

Reputation: 525

You have three mistakes

  • "'$line'" -> "$line"
  • final=echo -> final=$(echo ...)
  • $final.'.txt' -> $final'.txt'
#!/bin/bash
IFS=$'\n'
file=mails.txt
lines=$(cat ${file})

for line in ${lines}; do
   echo "'${line}'"
   final=$(echo "$line" | sed -e 's/^\.\*\(.*\)\*\./\1/')
   curl -XGET "https://google.es" > ${final}'.txt'                         
   sleep 2
done

IFS=""
exit ${?}

Upvotes: 1

Related Questions