Skip to main content
3 of 3
Typo, minor rephrasing
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Preserve read statement's last variable assignments outside of "while" loop

I am trying to echo the variables $f1, $f2, ... , outside of the while loop shown below. From what I understand, the scope of the variable is not correct. Therefore I tried a few of the workarounds as shown in the Bash FAQ:

while IFS=: read -r f1 f2 f3 f4 f5 f6 f7; do echo "Username: $f1. Home directory:$f6" done</etc/passwd echo $f1 

However, I can't seem to reproduce the fix(es) as shown in the link. Can someone provide an applied example on how to fix this issue?

User
  • 75
  • 2
  • 7