I created the following code:
#!/bin/bash
rdir="~/bin/Test/"
echo $rdir
echo $rdir"folderA"
/bin/mkdir -p $rdir"folderA"
# files is an array. () is used to enclose array elements and
# each array element enclosed by "".
files=(
"Apple"
"Apple\ Pie")
IFS="" # What is this for?
for f in ${files[@]}
do
echo "$rdir${f}"
/bin/touch "$rdir${f}"
/bin/ln -s "$rdir${f}" "$rdir${f}"_linktarget"
/bin/ln -s "$rdir${f}" "$rdirfolderA"${f}"_linktarget"
done
I call this code test2.sh and get the below results after executing it:
$ ./test2.sh
~/bin/Test/
~/bin/Test/folderA
./test2.sh: line 22: unexpected EOF while looking for matching `"'
./test2.sh: line 25: syntax error: unexpected end of file
$ ls -a
~ . .. test2.sh
Problems:
- The mkdir -p command did not create the folder.
- The touch command could not create files named according to the array elements. One of the array element contains two words with a space between them. I created the for loop to handle such array elements following the answer of Khushneet.
- I could not create soft link of the touch files and its target in the current directory or the sub-directory "folderA".
Questions:
How to solve these 3 problems.
What is IFS and how to use it?
Thanks.