So, I'm new at using bash script, but I am an experienced programmer in Java. I am trying to evaluate a string, by having it go through a loop that looks at each of its characters. It then needs to replace all whitespace with a hyphen character ("-"). Here's my code:
for a in "${newdirectory[@]}"; do
str="LDAUU_"
str+=$a
echo $str | awk -v ORS="" '{ gsub(/./,"&\n") ; print }' | \
while read char
do
if [[ $char == "whitespacecharacter" ]]
then
str+="-"
else
str+=$char
fi
done
The newdirectory variable is an array of user input, which was initially a single variable that was separated into the newdirectory array using the delimiter ",". The for loop also continues, but it's irrelevant to this section of the script. Also, I would prefer not to restructure my code completely. I need something that just evaluates the "char" variable in the while loop as a whitespace character. That's it. Thank you.