Question

I'm trying to search for the first matching directory with a wildcard in a bash shell script, it seems to be working fine on a few systems, and not on others. Is there any way around this to have it work on all Centos version? I am running 6.3, then it works, but Centos 6.4 on a VPS it doesn't work, it outputs files instead of just directory:

Here is what I got:

DAHDI=$(ls -d -1 /usr/src/dahdi-linux-complete* | head -n1);

cd "$DAHDI"

Any kind of help I can get on this is greatly appreciated.

Was it helpful?

Solution

You probably want to use find instead:

DAHDI=$(find /usr/src -maxdepth 1 -type d -name "dahdi-linux-complete*" | head -1)
cd "${DAHDI}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top