bash: Field Separator Variable

By default when using a for loop in bash the field separator is set to a space.

Example:

[[email protected] ~]$ for x in list:like:this; do echo $x; done  
list:like:this

One of the cool things about bash is that you can change this by setting a simple variable $IFS

[[email protected] ~]$ IFS=":"  
[[email protected] ~]$ for x in list:like:this; do echo $x; done  
list like this
Avatar
Benjamin Cane
Principal Engineer, Vice President

Principal Engineer focused on building cloud-native software solutions for financial platforms. Benjamin uses both his systems and software knowledge to build end-to-end platforms. Platforms purpose built for performance, and resiliency.

Next
Previous

Related