in bash how do I loop through directories starting with “abc” and the directory “special-dir”
up vote
-1
down vote
favorite
I have this code:
for dir in abc*/ ; do
echo $dir
done
This works, but I have one special directory (lets say its called "special-dir"). How can I add that to my loop, I am thinking somthing like:
for dir in abc*/ + "special-dir" ; do
echo $dir
done
Obvously that does not work!, but I can't quite think how to do this.
linux bash loops
|
show 1 more comment
up vote
-1
down vote
favorite
I have this code:
for dir in abc*/ ; do
echo $dir
done
This works, but I have one special directory (lets say its called "special-dir"). How can I add that to my loop, I am thinking somthing like:
for dir in abc*/ + "special-dir" ; do
echo $dir
done
Obvously that does not work!, but I can't quite think how to do this.
linux bash loops
1
Drop the + and you are good to go.
– Socowi
Nov 7 at 12:28
@Socowi ahhh... sweet :) .. if you want to add it as an answer I'll mark it up
– code_fodder
Nov 7 at 12:30
Thanks. There's already an answer here, so I pass.
– Socowi
Nov 7 at 12:31
@Socowi ok, yours was first (just), but thanks anyway : )
– code_fodder
Nov 7 at 12:32
Please, allow us to Google that for you: bash loop over multiple directories site:stackoverflow.com
– jww
Nov 7 at 15:54
|
show 1 more comment
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have this code:
for dir in abc*/ ; do
echo $dir
done
This works, but I have one special directory (lets say its called "special-dir"). How can I add that to my loop, I am thinking somthing like:
for dir in abc*/ + "special-dir" ; do
echo $dir
done
Obvously that does not work!, but I can't quite think how to do this.
linux bash loops
I have this code:
for dir in abc*/ ; do
echo $dir
done
This works, but I have one special directory (lets say its called "special-dir"). How can I add that to my loop, I am thinking somthing like:
for dir in abc*/ + "special-dir" ; do
echo $dir
done
Obvously that does not work!, but I can't quite think how to do this.
linux bash loops
linux bash loops
asked Nov 7 at 12:25
code_fodder
4,87563772
4,87563772
1
Drop the + and you are good to go.
– Socowi
Nov 7 at 12:28
@Socowi ahhh... sweet :) .. if you want to add it as an answer I'll mark it up
– code_fodder
Nov 7 at 12:30
Thanks. There's already an answer here, so I pass.
– Socowi
Nov 7 at 12:31
@Socowi ok, yours was first (just), but thanks anyway : )
– code_fodder
Nov 7 at 12:32
Please, allow us to Google that for you: bash loop over multiple directories site:stackoverflow.com
– jww
Nov 7 at 15:54
|
show 1 more comment
1
Drop the + and you are good to go.
– Socowi
Nov 7 at 12:28
@Socowi ahhh... sweet :) .. if you want to add it as an answer I'll mark it up
– code_fodder
Nov 7 at 12:30
Thanks. There's already an answer here, so I pass.
– Socowi
Nov 7 at 12:31
@Socowi ok, yours was first (just), but thanks anyway : )
– code_fodder
Nov 7 at 12:32
Please, allow us to Google that for you: bash loop over multiple directories site:stackoverflow.com
– jww
Nov 7 at 15:54
1
1
Drop the + and you are good to go.
– Socowi
Nov 7 at 12:28
Drop the + and you are good to go.
– Socowi
Nov 7 at 12:28
@Socowi ahhh... sweet :) .. if you want to add it as an answer I'll mark it up
– code_fodder
Nov 7 at 12:30
@Socowi ahhh... sweet :) .. if you want to add it as an answer I'll mark it up
– code_fodder
Nov 7 at 12:30
Thanks. There's already an answer here, so I pass.
– Socowi
Nov 7 at 12:31
Thanks. There's already an answer here, so I pass.
– Socowi
Nov 7 at 12:31
@Socowi ok, yours was first (just), but thanks anyway : )
– code_fodder
Nov 7 at 12:32
@Socowi ok, yours was first (just), but thanks anyway : )
– code_fodder
Nov 7 at 12:32
Please, allow us to Google that for you: bash loop over multiple directories site:stackoverflow.com
– jww
Nov 7 at 15:54
Please, allow us to Google that for you: bash loop over multiple directories site:stackoverflow.com
– jww
Nov 7 at 15:54
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The path expansion just expands the glob to list of the actual directories. Word list is space separated, so just use space to separate the next element of the list:
for dir in abc*/ special-dir ; do
echo "$dir"
done
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The path expansion just expands the glob to list of the actual directories. Word list is space separated, so just use space to separate the next element of the list:
for dir in abc*/ special-dir ; do
echo "$dir"
done
add a comment |
up vote
1
down vote
accepted
The path expansion just expands the glob to list of the actual directories. Word list is space separated, so just use space to separate the next element of the list:
for dir in abc*/ special-dir ; do
echo "$dir"
done
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The path expansion just expands the glob to list of the actual directories. Word list is space separated, so just use space to separate the next element of the list:
for dir in abc*/ special-dir ; do
echo "$dir"
done
The path expansion just expands the glob to list of the actual directories. Word list is space separated, so just use space to separate the next element of the list:
for dir in abc*/ special-dir ; do
echo "$dir"
done
answered Nov 7 at 12:29
choroba
152k14138199
152k14138199
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189439%2fin-bash-how-do-i-loop-through-directories-starting-with-abc-and-the-directory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Drop the + and you are good to go.
– Socowi
Nov 7 at 12:28
@Socowi ahhh... sweet :) .. if you want to add it as an answer I'll mark it up
– code_fodder
Nov 7 at 12:30
Thanks. There's already an answer here, so I pass.
– Socowi
Nov 7 at 12:31
@Socowi ok, yours was first (just), but thanks anyway : )
– code_fodder
Nov 7 at 12:32
Please, allow us to Google that for you: bash loop over multiple directories site:stackoverflow.com
– jww
Nov 7 at 15:54