Sunday, 14 August 2016

Wildcard in variable, Shell bash, how to do ? Variable=$variable2*





For me it worked:



diretorio=$(echo 'test 123'*)


but not worked when i used variable in quotes



Var2="test 123" 
diretorio=$(echo '$Var2'*)



How to solve it?


Answer



May I suggest an alternate approach? Instead of making a space-separated list of filenames (which will cause horrible confusion if any of the filenames contain spaces, e.g. "test 123"), use an array:



diretorio=("${Var2}"*)
doSomethingWithAllFiles "${diretorio[@]}"
for umDiretorio in "${diretorio[@]}"; do
doSomethingWithASingleFile "$umDiretorio"
done


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...