Advertisement
FranzVuttke

iter_over_txt_file_lines.sh

Jul 27th, 2024 (edited)
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.69 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. # Looping through the content of a file in Bash
  4. # source: https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash
  5.  
  6. # iterating over lines of text file
  7. #
  8. while read line; do
  9.   echo "$line"
  10. done <blt_devs.txt
  11.  
  12. # iterating over stdout returning directly from an app
  13. #
  14. bluetoothctl devices | while read line; do echo $line; done
  15. # or
  16. bluetoothctl devices | while read line || [[ -n $line ]]; do echo $line; done
  17. # or
  18. while read line; do echo $line; done < <(bluetoothctl devices)
  19. # what '< <' means:
  20. # see: What's the difference between <<, <<< and < < in bash?
  21. # https://askubuntu.com/questions/678915/whats-the-difference-between-and-in-bash
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement