I am writing a script that checks a certain directory for any sub-directories starting with a specific word.Here is my script thus far:#!/bin/bashfunction checkDirectory() {    themeDirectory=/usr/share/themes    iconDirectory=/usr/share/icons    # I don't know what to put for the regex.     regex=    if [ -d $themeDirectory/$regex && -d $iconDirectory/$regex ]; then       echo Directories exist.    else       echo Directories don't exist.    fi}So, how would you use regex to check if a particular directory has any folders starting with a specific word?
Use regex to check if particular directory has folders starting with specific word
bash;command line;regular expression
If you only want to find directories matching a given pattern/prefix, I think you could just use find:find /target/directory -type d -name prefix*or, if you only want immediate subdirectories:find /target/directory -maxdepth 1 -type d -name prefix*Of course, there's also -regexif you need an actual regex match. (caveat: I can't remember if -maxdepth is a gnu-ism.)(update) Right, you wanted an if statement. Find always returns a zero, so we can't use the return value to check if anything was found (unlike with grep). But we can e.g. count the lines. Pipe the output through wc to get the count, then see if it's not zero:if [ $(find /target/directory -type d -name prefix* | wc -l ) != 0 ] ; then    echo something was foundelse    echo nope, didn't find anythingfi