I am trying to write a script then search for all the directories with the given substring but I am getting the following error.
I have no idea why this is happening.. can someone please guide me ?
#!/bin/bash echo $1 for recordings in $1/*/ ; do echo $recordings | grep -q "XavierA" echo $? if ["$?" -eq 0];then echo "found." fi done The output is this
0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found 0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found 0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found 0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found 0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found 0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found 0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found 0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found 0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found 0 ./readallfiles.sh: line 7: [0: command not found 1 ./readallfiles.sh: line 7: [0: command not found
$1/*/should be"$1"/*/to work right with directory names with spaces and glob characters; and the remaining lines would be better written asif [[ $recordings = *XavierA* ]]; then echo "found"; fi-- though you also just have your whole glob search for"$1"/*XavierA*/and avoid the need for a loop altogether. See BashFAQ #4 re: best practices for counting how many directory entries match a pattern.