IFS to read systeminfos

by user294015   Last Updated April 16, 2018 12:02 PM

I tried to read some Systeminfos and put into variables:

df -k | grep /dev/mmcblk0p1 | IFS=" " read -r device blocks used available use_percent mounted_on

but did not work, all variables are emty...

Tags : bash ifs


Answers 1


The issue is not the IFS, it's because in bash (and certain other shells) the RHS of a pipeline is executed in a subshell.

A simple alternative is to use process substitution to keep the read in the parent shell:

read -r device blocks used available use_percent mounted_on < <(df -k | grep /dev/mmcblk0p1)

See Bash: Variable assignment doesn't seem to 'stick'

steeldriver
steeldriver
April 16, 2018 12:00 PM

Related Questions



Deleting history from ~/.bash_history

Updated September 04, 2017 05:02 AM