IFS Input field separator and Array in bash

 By default, in bash we have IFS set as space(' ')

What we will learn

  • What exactly is Input Field Separator
  • Create arrays in bash
  • Access arrays in shell
  • Get length of array

What exactly is Input Field Separator

Input Field Seperator 

Create Arrays from String in Shell

To create a array from a shell:

IFS=' '
input="coffee is hot, water is cold"
array=($input)
echo "len: "${array[@]}

Check if String contains a substring

if [[ ! "$str" =~ "~" ]] ; then
echo "It contains there!"
fi

Check if String contains a substring OR AND another string

if [[ "$str" =~ ":" || "$str" =~ "~" ]]; then
echo "Its there!"
fi

Comments