On OS X, /usr/bin/sw_vers -productVersion will output the current computer’s OS version: I tried cut, but I don't know how to specify the last field with -f. In some cases, we might need to split the string data to perform some specific tasks. separated - bash split string into variables . *As we'll loop over characters in original string, we'll pass each character into scratch variable #char for easier reference. How do I split a string on a delimiter in Bash?, You can set the internal field separator (IFS) variable, and then let it parse into an array. I recently found myself needing to iterate over a bunch of '/' separated strings on the command line and extract just the text after the last '/'. Here's the Bash documentation for the concept known as "word-splitting" The internal field separator. For the record, here is the old solution: # # OLD CODE # Update: Aug/2016: I've encountered a bug in Bash where this splitting doesn't work as expected! Recently, while optimizing one of my scripts that powers my VPS Showdown posts, I wanted to take a string, split it by the colon : character and assign it to multiple variables that could be referenced. The string is passed as an argument. Bash split string into array by delimiter. array=( H E L L O ) # you don’t even need quotes array[0] $ = H. if you wanted to accept other ascii chars (say you’re converting to hex for some reason) array=(H E L L O “#” “!” ) #some chars you’ll want to use the quotes. Registered: Sep 2010. Split variable into multiple variables. Senior Member . Tag: ... which any remotely modern bash always will when invoked as bash; even if /bin/sh points to the same executable, it tells bash to disable many of its extensions from the POSIX spec. How to split one string into multiple variables in bash shell? #! In Java terms, this list of records is similar to the type of List