in CODING, Tips & Tricks

Another Thing I Keep Forgetting!

Every time I write a Bash script that loops through something, I test printing out the variable and it always splits the spaces across new lines so an app named ‘jHelper GUI 1.0.app’ ends up as:

jHelper
GUI
1.0.app

The thing I keep forgetting to sort this is IFS! so I just need to do the following:

#!/usr/bin/env bash

IFS=$'\n'

# Loop through apps and print out basename
for app in /Applications/*; do
    echo "$(basename ${app})"
done
unset IFS