A previous post showed how Emacs can read an environment variable (containing space-separated project directories) to set up multiple projects. To process the same environment variable in Bash, we will need a way of spliting a space-separated string into an array of the space-separated elements. The following script accomplishes this task.
#!/bin/sh
declare -a array
space_sep_string="aa bb cc dd"
array=(${space_sep_string// / })
for i in ${array[@]}; do
echo $i
done
4 comments:
array=(${space_sep_string// / })
you forgot the parenthese ;)
Thanks Staef for catching the mistake.
Thanks for good hint!
array=( $(echo space_sep_string) )
Post a Comment