0

I had to write a bash script that have to find the directories in the current directory and that directories must have a name that start with a letter of the alphabet [A-z]. For shell I wrote:

find . -maxdepth 1 -name '[[:alpha:]]*' -type d 

and it's ok. But in the script I wrote:

#! /bin/bash files=$(find . -maxdepth 1 -name '[[:alpha:]]*' -type d) for FILE in $files; do echo 'you are in', $FILE; done; 

But, when it finds a directory with whitespace (ex. ./New Directory) the output is

./New Directory 

as it were 2 different directories. Why? How can i resolve this problem?

1
  • 2
    By the time files is set, it is too late for quoting $FILE to make a difference. mywiki.wooledge.org/BashFAQ/001 Commented Dec 24, 2015 at 16:58

2 Answers 2

1
find -maxdepth 1 -type d -regextype posix-awk -regex ".*/[A-Z].*" -exec echo "you are in" {} \; 
Sign up to request clarification or add additional context in comments.

Comments

1

This may work for you :

find . -maxdepth 1 -name '[[:alpha:]]*' -type d | sed 's/^/You are in /' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.