Jay Kim
Jay Kim

Reputation: 11

Recognizing end of pasted contents even without a terminating newline in bash

I am trying to dig list of domains so that I can look up only txt records.

Here's my script.

#!/bin/bash

echo "Please Enter the Domains (Multiple Domains will work):"
while read domains || [[ -n "$domains" ]]; do      
echo
    dig TXT $domains | grep TXT
done

It works, but it will always ignore the last text from pasted input. I have to manually press return key to get it work.

Here's my testing results

$sh test.sh 
Please Enter the Domains (Multiple Domains will work):
1.1.1.1
1.1.1.2
1.1.1.3
1.1.1.4 <---- these are copy and paste from clipboard

; <<>> DiG 9.8.3-P1 <<>> TXT 1.1.1.1
;1.1.1.1.           IN  TXT

; <<>> DiG 9.8.3-P1 <<>> TXT 1.1.1.2
;1.1.1.2.           IN  TXT

; <<>> DiG 9.8.3-P1 <<>> TXT 1.1.1.3
;1.1.1.3.           IN  TXT

(I have to press return at this point, to get last dig result)

; <<>> DiG 9.8.3-P1 <<>> TXT 1.1.1.4
;1.1.1.4.           IN  TXT

I've tried hours and hours searching through Google to fix it, but couldn't find the resolution. Any insights will be appreciated.

Thanks

Upvotes: 1

Views: 71

Answers (0)

Related Questions