I use the following code as variable in a script:
match=$( ls | grep -i "$search")
this is then used in an if statement:
if [ "$match" ]; then
echo "matches found"
else
echo "no matches found"
fi
what would be an alternative if I did not want to use find? ShellCheck recommends:
ls /directory/target_file_pattern
but I do not get the syntax right to get the same result. also I want no output when there are no matches for the if statement to work.
Aucun commentaire:
Enregistrer un commentaire