问题
I have this piece of code to match the folder name:
#!/bin/bash
for dir in teste/*
do
if [ "$dir" = 1 ]; then
echo "folder 1";
fi
if [ "$dir" = 2 ]; then
echo "folder 2";
fi
done
And I have a directory called teste/1/ and teste/2/ After running the script above, my output is nothing! There are no errors...
Do you know how to solve it? I don't know why this happens
回答1:
Variable dir
does not contain 1
or 2
but teste/1
or teste/2
.
Use, e.g.:
if [ "$dir" = "teste/1" ]; then
来源:https://stackoverflow.com/questions/56821197/matching-folder-name-using-bash