Skip to content
Advertisement

Split lines from a file into variables (accepting spaces) BASH

I need a script in bash that reads a file and recognize an delimiter (“;”) and store the values between the delimiters into variables to build a dialog menu later.

What i’ve done:

JavaScript

the file that it reads is :

JavaScript

And the output:

JavaScript

Advertisement

Answer

With a while you can split a line into a lot of vars in 1 call.
You need to temporary change the FieldSep (IFS) into a ;
And avoid an extra call to cat: do not use cat $file | .. but use < $file

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement