I have written a small program to get the list of all files in a directory and concatenating them to a single string variable. Here’s the code
#!/bin/bash
dir ="/home/user/myfolder/abc"
res=" "
for f in $( ls $dir ); do
res="$res $f"
done
echo $res
However I am getting the following error
dir: cannot access =/home/user/myfolder/abc: No such file or directory
I have set all the required permissions, whats the solution?
Remove the space between the assignment:
Do this:
Each language has its own syntax, and bash scripting requires no spaces between
left_value=right_valueduring assignments; as you see, it’s simply a matter of syntax.