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
array=(${space_sep_string// / })
ReplyDeleteyou forgot the parenthese ;)
Thanks Staef for catching the mistake.
ReplyDeleteThanks for good hint!
ReplyDeletearray=( $(echo space_sep_string) )
ReplyDelete