How to loop variables with spaces in bash? Jun 16, 2022 I had this problem when I wanted to loop the arguments of a script, and those arguments could have spaces in them. The solution is to first convert the arguments into an array, and then loop the array by using the array notation: args=( "$@" ) for arg in "${args[@]}; do echo "$arg" done