Issue
I have a folder with path ./Ur/postProcessing/forces
, and it includes two sub_folders name 0
and 100
, now I want to list the name of these two sub_folders into a variable, like time=(0 100)
.
My code is
dirs=(./Ur/postProcessing/forces/*/)
timeDirs=$(for dir in "${dirs[@]}"
do
echo "$dir"
done)
echo "$timeDirs"
And I get the following results:
./Ur/postProcessing/forcs/0/
./Ur/postProcessing/forces/100/
How can I get (0 100) as a variable? Thanks!
Solution
You can do this in your scripts:
# change directory
cd ./Ur/postProcessing/forces/
# read all sub-directories in shell array dirs
dirs=(*/)
# check content of dirs
declare -p dirs
Answered By - anubhava Answer Checked By - David Goodson (WPSolving Volunteer)