Bash array with folder paths and wildcards The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsWhy is printf better than echo?Why does my shell script choke on whitespace or other special characters?When is double-quoting necessary?List of top level folders with contents no younger than 30 daysBash script error with strings with paths that have spaces and wildcardsfind delete shows “No such file or directory”Exit bash when find gets to a folder with permission deniedHow to set up a pre-defined variable with multiple directory paths to use with the find commandregarding recursive deleting of a specific file typeHow to store a path built with wildcards and containing with spaces into a variableFind and delete folders within directory that are older than x daysCheck if files are deletedCleanup Script for macOS

Can the prologue be the backstory of your main character?

"... to apply for a visa" or "... and applied for a visa"?

Does Parliament need to approve the new Brexit delay to 31 October 2019?

How to split my screen on my Macbook Air?

Would an alien lifeform be able to achieve space travel if lacking in vision?

Cooking pasta in a water boiler

Working through the single responsibility principle (SRP) in Python when calls are expensive

Am I ethically obligated to go into work on an off day if the reason is sudden?

How are presidential pardons supposed to be used?

What information about me do stores get via my credit card?

How can I protect witches in combat who wear limited clothing?

Windows 10: How to Lock (not sleep) laptop on lid close?

Difference between "generating set" and free product?

How is simplicity better than precision and clarity in prose?

Create an outline of font

Did God make two great lights or did He make the great light two?

The variadic template constructor of my class cannot modify my class members, why is that so?

Wall plug outlet change

Semisimplicity of the category of coherent sheaves?

University's motivation for having tenure-track positions

The following signatures were invalid: EXPKEYSIG 1397BC53640DB551

Can a novice safely splice in wire to lengthen 5V charging cable?

Mortgage adviser recommends a longer term than necessary combined with overpayments

Arduino Pro Micro - switch off LEDs



Bash array with folder paths and wildcards



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election ResultsWhy is printf better than echo?Why does my shell script choke on whitespace or other special characters?When is double-quoting necessary?List of top level folders with contents no younger than 30 daysBash script error with strings with paths that have spaces and wildcardsfind delete shows “No such file or directory”Exit bash when find gets to a folder with permission deniedHow to set up a pre-defined variable with multiple directory paths to use with the find commandregarding recursive deleting of a specific file typeHow to store a path built with wildcards and containing with spaces into a variableFind and delete folders within directory that are older than x daysCheck if files are deletedCleanup Script for macOS



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















enter image description here



Given the above folder paths, I am trying to write a script that will delete files older than a certain amount of days. I am trying to use some more advanced techniques than just hard coding the paths (my real life examples has ALOT more folders). Here is what I have so far:



#!/bin/bash

FILEAGE=15

#Array of folders to clean
dir_array=(
"/srv/*/folderA"
"/srv/level1D/*/folderA"
)


#function to be used for deleting files. Needs to be called with a path
function dir_delete()
echo "Deleting:"
find $1 -type f -mindepth 1 -maxdepth 1 -mtime +$FILEAGE -delete -print
echo ""


echo "##### Looping through dir_array array and using dir_delete function to delete files older than $FILEAGE days #####"
for d in "$dir_array[@]";do
if [ -d $d ];then

echo "##### Deleting all files older than $FILEAGE in $d #####"
dir_delete $d

else
echo "##### Did not find directory: $d #####"
echo ""
fi

done


My script is returning that it can't find the directories like so:



Did not find directory: /srv/*/folderA


Note: There will be files throughout these folders under 15 days that can't be deleted.



Update



Using @Kusalananda suggestion '/srv/'*'/folderA' fixed it for me. I'm leaving the wrong code in my original post above should anyone want to see what I was doing wrong.










share|improve this question
























  • I don't think you can provide multiple root paths with e. g. find /path/*/to/places. The easiest option for me off the top of my head would be for rootpath in /srv/*/folderA; do find "$rootpath" [...]; done.

    – DopeGhoti
    yesterday











  • * will not be expanded when it's quoted. Do you know that the mtime of a directory only updates when a file is deleted or created in it?

    – Kusalananda
    yesterday






  • 1





    @DopeGhoti find does support multiple search paths, but the * is expanded in the wrong place. It should be expanded in the array, not in the execution of the find command.

    – Kusalananda
    yesterday

















1















enter image description here



Given the above folder paths, I am trying to write a script that will delete files older than a certain amount of days. I am trying to use some more advanced techniques than just hard coding the paths (my real life examples has ALOT more folders). Here is what I have so far:



#!/bin/bash

FILEAGE=15

#Array of folders to clean
dir_array=(
"/srv/*/folderA"
"/srv/level1D/*/folderA"
)


#function to be used for deleting files. Needs to be called with a path
function dir_delete()
echo "Deleting:"
find $1 -type f -mindepth 1 -maxdepth 1 -mtime +$FILEAGE -delete -print
echo ""


echo "##### Looping through dir_array array and using dir_delete function to delete files older than $FILEAGE days #####"
for d in "$dir_array[@]";do
if [ -d $d ];then

echo "##### Deleting all files older than $FILEAGE in $d #####"
dir_delete $d

else
echo "##### Did not find directory: $d #####"
echo ""
fi

done


My script is returning that it can't find the directories like so:



Did not find directory: /srv/*/folderA


Note: There will be files throughout these folders under 15 days that can't be deleted.



Update



Using @Kusalananda suggestion '/srv/'*'/folderA' fixed it for me. I'm leaving the wrong code in my original post above should anyone want to see what I was doing wrong.










share|improve this question
























  • I don't think you can provide multiple root paths with e. g. find /path/*/to/places. The easiest option for me off the top of my head would be for rootpath in /srv/*/folderA; do find "$rootpath" [...]; done.

    – DopeGhoti
    yesterday











  • * will not be expanded when it's quoted. Do you know that the mtime of a directory only updates when a file is deleted or created in it?

    – Kusalananda
    yesterday






  • 1





    @DopeGhoti find does support multiple search paths, but the * is expanded in the wrong place. It should be expanded in the array, not in the execution of the find command.

    – Kusalananda
    yesterday













1












1








1


0






enter image description here



Given the above folder paths, I am trying to write a script that will delete files older than a certain amount of days. I am trying to use some more advanced techniques than just hard coding the paths (my real life examples has ALOT more folders). Here is what I have so far:



#!/bin/bash

FILEAGE=15

#Array of folders to clean
dir_array=(
"/srv/*/folderA"
"/srv/level1D/*/folderA"
)


#function to be used for deleting files. Needs to be called with a path
function dir_delete()
echo "Deleting:"
find $1 -type f -mindepth 1 -maxdepth 1 -mtime +$FILEAGE -delete -print
echo ""


echo "##### Looping through dir_array array and using dir_delete function to delete files older than $FILEAGE days #####"
for d in "$dir_array[@]";do
if [ -d $d ];then

echo "##### Deleting all files older than $FILEAGE in $d #####"
dir_delete $d

else
echo "##### Did not find directory: $d #####"
echo ""
fi

done


My script is returning that it can't find the directories like so:



Did not find directory: /srv/*/folderA


Note: There will be files throughout these folders under 15 days that can't be deleted.



Update



Using @Kusalananda suggestion '/srv/'*'/folderA' fixed it for me. I'm leaving the wrong code in my original post above should anyone want to see what I was doing wrong.










share|improve this question
















enter image description here



Given the above folder paths, I am trying to write a script that will delete files older than a certain amount of days. I am trying to use some more advanced techniques than just hard coding the paths (my real life examples has ALOT more folders). Here is what I have so far:



#!/bin/bash

FILEAGE=15

#Array of folders to clean
dir_array=(
"/srv/*/folderA"
"/srv/level1D/*/folderA"
)


#function to be used for deleting files. Needs to be called with a path
function dir_delete()
echo "Deleting:"
find $1 -type f -mindepth 1 -maxdepth 1 -mtime +$FILEAGE -delete -print
echo ""


echo "##### Looping through dir_array array and using dir_delete function to delete files older than $FILEAGE days #####"
for d in "$dir_array[@]";do
if [ -d $d ];then

echo "##### Deleting all files older than $FILEAGE in $d #####"
dir_delete $d

else
echo "##### Did not find directory: $d #####"
echo ""
fi

done


My script is returning that it can't find the directories like so:



Did not find directory: /srv/*/folderA


Note: There will be files throughout these folders under 15 days that can't be deleted.



Update



Using @Kusalananda suggestion '/srv/'*'/folderA' fixed it for me. I'm leaving the wrong code in my original post above should anyone want to see what I was doing wrong.







bash shell-script shell wildcards variable






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







JuanD

















asked yesterday









JuanDJuanD

2616




2616












  • I don't think you can provide multiple root paths with e. g. find /path/*/to/places. The easiest option for me off the top of my head would be for rootpath in /srv/*/folderA; do find "$rootpath" [...]; done.

    – DopeGhoti
    yesterday











  • * will not be expanded when it's quoted. Do you know that the mtime of a directory only updates when a file is deleted or created in it?

    – Kusalananda
    yesterday






  • 1





    @DopeGhoti find does support multiple search paths, but the * is expanded in the wrong place. It should be expanded in the array, not in the execution of the find command.

    – Kusalananda
    yesterday

















  • I don't think you can provide multiple root paths with e. g. find /path/*/to/places. The easiest option for me off the top of my head would be for rootpath in /srv/*/folderA; do find "$rootpath" [...]; done.

    – DopeGhoti
    yesterday











  • * will not be expanded when it's quoted. Do you know that the mtime of a directory only updates when a file is deleted or created in it?

    – Kusalananda
    yesterday






  • 1





    @DopeGhoti find does support multiple search paths, but the * is expanded in the wrong place. It should be expanded in the array, not in the execution of the find command.

    – Kusalananda
    yesterday
















I don't think you can provide multiple root paths with e. g. find /path/*/to/places. The easiest option for me off the top of my head would be for rootpath in /srv/*/folderA; do find "$rootpath" [...]; done.

– DopeGhoti
yesterday





I don't think you can provide multiple root paths with e. g. find /path/*/to/places. The easiest option for me off the top of my head would be for rootpath in /srv/*/folderA; do find "$rootpath" [...]; done.

– DopeGhoti
yesterday













* will not be expanded when it's quoted. Do you know that the mtime of a directory only updates when a file is deleted or created in it?

– Kusalananda
yesterday





* will not be expanded when it's quoted. Do you know that the mtime of a directory only updates when a file is deleted or created in it?

– Kusalananda
yesterday




1




1





@DopeGhoti find does support multiple search paths, but the * is expanded in the wrong place. It should be expanded in the array, not in the execution of the find command.

– Kusalananda
yesterday





@DopeGhoti find does support multiple search paths, but the * is expanded in the wrong place. It should be expanded in the array, not in the execution of the find command.

– Kusalananda
yesterday










2 Answers
2






active

oldest

votes


















1














The shell globbing pattern * is not expanded within double quotes. This means that your loop



for d in "$dir_array[@]";do


is looping over patterns. In your call to dir_delete, you use the patterns unquoted, so they would be expand there (but it never gets there). The function would however only use the first word of whatever matches the pattern in the call to find.



The real show-stopper is that the patterns will also be expanded in the [ -d $d ] test, which is awkward since the -d test only ever takes a single pathname. This is, in the end, why the script fails.



Instead, make sure that the patterns are properly expanded when assigning to dir_array:



dir_array=(
/srv/*/folderA
/srv/level1D/*/folderA
)


If folderA or some other part of the pathnames contains spaces etc., that part of the pathname should be quoted, but the * should not be quoted.



Also remember to double quote the expansions of all variables, unless you know the contexts in which they don't need to be quoted.



There may be quoting issues with the following lines:



  • if [ -d $d ];then

  • find $1 -type f -mindepth 1 -maxdepth 1 -mtime +$FILEAGE -delete -print

  • dir_delete $d

Also consider using printf rather than echo when outputting variable data.



Related:



  • Why does my shell script choke on whitespace or other special characters?

  • When is double-quoting necessary?

  • Why is printf better than echo?





share|improve this answer

























  • Your suggestion of using '/srv/'*'/folderA' worked for me. Thanks again.

    – JuanD
    yesterday



















1














You can do this with the extended glob option which will allow you to expand wildcards within a variable with *()



shopt -s extglob
dir_array=(
"/srv/*(*)/folderA"
"/srv/level1D/*(*)/folderA"
)


The expansion would happen at the for d in ... which I think is the correct point.






share|improve this answer




















  • 1





    No, just use /srv/*/folderA unquoted (or '/srv/'*'/folderA'). It will expand correctly at the time of assigning to dir_array.

    – Kusalananda
    yesterday












  • @XrXca your suggestion gave me the following message: [: /srv/level1A/folderA: binary operator expected

    – JuanD
    yesterday











  • @Kusalananda I think your solution is working. Testing a few more scenarios now. Thank you much. I dont know if I can accept a sub comment as an answer.

    – JuanD
    yesterday











  • @Kusalananda: Either should work, I tend to use the () construct when I'm using extglobs just because it's obvious it's not "normal", when a block of code is copied from one script to another, and I use the @(A|B|C).construct quite a bit.so it's "similar' in my mind.

    – XrXca
    yesterday











  • @XrXca I'm just looking at the code and noticing that the only thing the script is using bash for (and not /bin/sh) is that single array. Changing it to set -- patterns would allow it to run under /bin/sh (the loop would loop over "$@" instead). My personal preference is to use /bin/sh, which is why I commented the way I did. Apart from that, you may well be right.

    – Kusalananda
    yesterday












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512148%2fbash-array-with-folder-paths-and-wildcards%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The shell globbing pattern * is not expanded within double quotes. This means that your loop



for d in "$dir_array[@]";do


is looping over patterns. In your call to dir_delete, you use the patterns unquoted, so they would be expand there (but it never gets there). The function would however only use the first word of whatever matches the pattern in the call to find.



The real show-stopper is that the patterns will also be expanded in the [ -d $d ] test, which is awkward since the -d test only ever takes a single pathname. This is, in the end, why the script fails.



Instead, make sure that the patterns are properly expanded when assigning to dir_array:



dir_array=(
/srv/*/folderA
/srv/level1D/*/folderA
)


If folderA or some other part of the pathnames contains spaces etc., that part of the pathname should be quoted, but the * should not be quoted.



Also remember to double quote the expansions of all variables, unless you know the contexts in which they don't need to be quoted.



There may be quoting issues with the following lines:



  • if [ -d $d ];then

  • find $1 -type f -mindepth 1 -maxdepth 1 -mtime +$FILEAGE -delete -print

  • dir_delete $d

Also consider using printf rather than echo when outputting variable data.



Related:



  • Why does my shell script choke on whitespace or other special characters?

  • When is double-quoting necessary?

  • Why is printf better than echo?





share|improve this answer

























  • Your suggestion of using '/srv/'*'/folderA' worked for me. Thanks again.

    – JuanD
    yesterday
















1














The shell globbing pattern * is not expanded within double quotes. This means that your loop



for d in "$dir_array[@]";do


is looping over patterns. In your call to dir_delete, you use the patterns unquoted, so they would be expand there (but it never gets there). The function would however only use the first word of whatever matches the pattern in the call to find.



The real show-stopper is that the patterns will also be expanded in the [ -d $d ] test, which is awkward since the -d test only ever takes a single pathname. This is, in the end, why the script fails.



Instead, make sure that the patterns are properly expanded when assigning to dir_array:



dir_array=(
/srv/*/folderA
/srv/level1D/*/folderA
)


If folderA or some other part of the pathnames contains spaces etc., that part of the pathname should be quoted, but the * should not be quoted.



Also remember to double quote the expansions of all variables, unless you know the contexts in which they don't need to be quoted.



There may be quoting issues with the following lines:



  • if [ -d $d ];then

  • find $1 -type f -mindepth 1 -maxdepth 1 -mtime +$FILEAGE -delete -print

  • dir_delete $d

Also consider using printf rather than echo when outputting variable data.



Related:



  • Why does my shell script choke on whitespace or other special characters?

  • When is double-quoting necessary?

  • Why is printf better than echo?





share|improve this answer

























  • Your suggestion of using '/srv/'*'/folderA' worked for me. Thanks again.

    – JuanD
    yesterday














1












1








1







The shell globbing pattern * is not expanded within double quotes. This means that your loop



for d in "$dir_array[@]";do


is looping over patterns. In your call to dir_delete, you use the patterns unquoted, so they would be expand there (but it never gets there). The function would however only use the first word of whatever matches the pattern in the call to find.



The real show-stopper is that the patterns will also be expanded in the [ -d $d ] test, which is awkward since the -d test only ever takes a single pathname. This is, in the end, why the script fails.



Instead, make sure that the patterns are properly expanded when assigning to dir_array:



dir_array=(
/srv/*/folderA
/srv/level1D/*/folderA
)


If folderA or some other part of the pathnames contains spaces etc., that part of the pathname should be quoted, but the * should not be quoted.



Also remember to double quote the expansions of all variables, unless you know the contexts in which they don't need to be quoted.



There may be quoting issues with the following lines:



  • if [ -d $d ];then

  • find $1 -type f -mindepth 1 -maxdepth 1 -mtime +$FILEAGE -delete -print

  • dir_delete $d

Also consider using printf rather than echo when outputting variable data.



Related:



  • Why does my shell script choke on whitespace or other special characters?

  • When is double-quoting necessary?

  • Why is printf better than echo?





share|improve this answer















The shell globbing pattern * is not expanded within double quotes. This means that your loop



for d in "$dir_array[@]";do


is looping over patterns. In your call to dir_delete, you use the patterns unquoted, so they would be expand there (but it never gets there). The function would however only use the first word of whatever matches the pattern in the call to find.



The real show-stopper is that the patterns will also be expanded in the [ -d $d ] test, which is awkward since the -d test only ever takes a single pathname. This is, in the end, why the script fails.



Instead, make sure that the patterns are properly expanded when assigning to dir_array:



dir_array=(
/srv/*/folderA
/srv/level1D/*/folderA
)


If folderA or some other part of the pathnames contains spaces etc., that part of the pathname should be quoted, but the * should not be quoted.



Also remember to double quote the expansions of all variables, unless you know the contexts in which they don't need to be quoted.



There may be quoting issues with the following lines:



  • if [ -d $d ];then

  • find $1 -type f -mindepth 1 -maxdepth 1 -mtime +$FILEAGE -delete -print

  • dir_delete $d

Also consider using printf rather than echo when outputting variable data.



Related:



  • Why does my shell script choke on whitespace or other special characters?

  • When is double-quoting necessary?

  • Why is printf better than echo?






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









KusalanandaKusalananda

141k18263439




141k18263439












  • Your suggestion of using '/srv/'*'/folderA' worked for me. Thanks again.

    – JuanD
    yesterday


















  • Your suggestion of using '/srv/'*'/folderA' worked for me. Thanks again.

    – JuanD
    yesterday

















Your suggestion of using '/srv/'*'/folderA' worked for me. Thanks again.

– JuanD
yesterday






Your suggestion of using '/srv/'*'/folderA' worked for me. Thanks again.

– JuanD
yesterday














1














You can do this with the extended glob option which will allow you to expand wildcards within a variable with *()



shopt -s extglob
dir_array=(
"/srv/*(*)/folderA"
"/srv/level1D/*(*)/folderA"
)


The expansion would happen at the for d in ... which I think is the correct point.






share|improve this answer




















  • 1





    No, just use /srv/*/folderA unquoted (or '/srv/'*'/folderA'). It will expand correctly at the time of assigning to dir_array.

    – Kusalananda
    yesterday












  • @XrXca your suggestion gave me the following message: [: /srv/level1A/folderA: binary operator expected

    – JuanD
    yesterday











  • @Kusalananda I think your solution is working. Testing a few more scenarios now. Thank you much. I dont know if I can accept a sub comment as an answer.

    – JuanD
    yesterday











  • @Kusalananda: Either should work, I tend to use the () construct when I'm using extglobs just because it's obvious it's not "normal", when a block of code is copied from one script to another, and I use the @(A|B|C).construct quite a bit.so it's "similar' in my mind.

    – XrXca
    yesterday











  • @XrXca I'm just looking at the code and noticing that the only thing the script is using bash for (and not /bin/sh) is that single array. Changing it to set -- patterns would allow it to run under /bin/sh (the loop would loop over "$@" instead). My personal preference is to use /bin/sh, which is why I commented the way I did. Apart from that, you may well be right.

    – Kusalananda
    yesterday
















1














You can do this with the extended glob option which will allow you to expand wildcards within a variable with *()



shopt -s extglob
dir_array=(
"/srv/*(*)/folderA"
"/srv/level1D/*(*)/folderA"
)


The expansion would happen at the for d in ... which I think is the correct point.






share|improve this answer




















  • 1





    No, just use /srv/*/folderA unquoted (or '/srv/'*'/folderA'). It will expand correctly at the time of assigning to dir_array.

    – Kusalananda
    yesterday












  • @XrXca your suggestion gave me the following message: [: /srv/level1A/folderA: binary operator expected

    – JuanD
    yesterday











  • @Kusalananda I think your solution is working. Testing a few more scenarios now. Thank you much. I dont know if I can accept a sub comment as an answer.

    – JuanD
    yesterday











  • @Kusalananda: Either should work, I tend to use the () construct when I'm using extglobs just because it's obvious it's not "normal", when a block of code is copied from one script to another, and I use the @(A|B|C).construct quite a bit.so it's "similar' in my mind.

    – XrXca
    yesterday











  • @XrXca I'm just looking at the code and noticing that the only thing the script is using bash for (and not /bin/sh) is that single array. Changing it to set -- patterns would allow it to run under /bin/sh (the loop would loop over "$@" instead). My personal preference is to use /bin/sh, which is why I commented the way I did. Apart from that, you may well be right.

    – Kusalananda
    yesterday














1












1








1







You can do this with the extended glob option which will allow you to expand wildcards within a variable with *()



shopt -s extglob
dir_array=(
"/srv/*(*)/folderA"
"/srv/level1D/*(*)/folderA"
)


The expansion would happen at the for d in ... which I think is the correct point.






share|improve this answer















You can do this with the extended glob option which will allow you to expand wildcards within a variable with *()



shopt -s extglob
dir_array=(
"/srv/*(*)/folderA"
"/srv/level1D/*(*)/folderA"
)


The expansion would happen at the for d in ... which I think is the correct point.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









XrXcaXrXca

813




813







  • 1





    No, just use /srv/*/folderA unquoted (or '/srv/'*'/folderA'). It will expand correctly at the time of assigning to dir_array.

    – Kusalananda
    yesterday












  • @XrXca your suggestion gave me the following message: [: /srv/level1A/folderA: binary operator expected

    – JuanD
    yesterday











  • @Kusalananda I think your solution is working. Testing a few more scenarios now. Thank you much. I dont know if I can accept a sub comment as an answer.

    – JuanD
    yesterday











  • @Kusalananda: Either should work, I tend to use the () construct when I'm using extglobs just because it's obvious it's not "normal", when a block of code is copied from one script to another, and I use the @(A|B|C).construct quite a bit.so it's "similar' in my mind.

    – XrXca
    yesterday











  • @XrXca I'm just looking at the code and noticing that the only thing the script is using bash for (and not /bin/sh) is that single array. Changing it to set -- patterns would allow it to run under /bin/sh (the loop would loop over "$@" instead). My personal preference is to use /bin/sh, which is why I commented the way I did. Apart from that, you may well be right.

    – Kusalananda
    yesterday













  • 1





    No, just use /srv/*/folderA unquoted (or '/srv/'*'/folderA'). It will expand correctly at the time of assigning to dir_array.

    – Kusalananda
    yesterday












  • @XrXca your suggestion gave me the following message: [: /srv/level1A/folderA: binary operator expected

    – JuanD
    yesterday











  • @Kusalananda I think your solution is working. Testing a few more scenarios now. Thank you much. I dont know if I can accept a sub comment as an answer.

    – JuanD
    yesterday











  • @Kusalananda: Either should work, I tend to use the () construct when I'm using extglobs just because it's obvious it's not "normal", when a block of code is copied from one script to another, and I use the @(A|B|C).construct quite a bit.so it's "similar' in my mind.

    – XrXca
    yesterday











  • @XrXca I'm just looking at the code and noticing that the only thing the script is using bash for (and not /bin/sh) is that single array. Changing it to set -- patterns would allow it to run under /bin/sh (the loop would loop over "$@" instead). My personal preference is to use /bin/sh, which is why I commented the way I did. Apart from that, you may well be right.

    – Kusalananda
    yesterday








1




1





No, just use /srv/*/folderA unquoted (or '/srv/'*'/folderA'). It will expand correctly at the time of assigning to dir_array.

– Kusalananda
yesterday






No, just use /srv/*/folderA unquoted (or '/srv/'*'/folderA'). It will expand correctly at the time of assigning to dir_array.

– Kusalananda
yesterday














@XrXca your suggestion gave me the following message: [: /srv/level1A/folderA: binary operator expected

– JuanD
yesterday





@XrXca your suggestion gave me the following message: [: /srv/level1A/folderA: binary operator expected

– JuanD
yesterday













@Kusalananda I think your solution is working. Testing a few more scenarios now. Thank you much. I dont know if I can accept a sub comment as an answer.

– JuanD
yesterday





@Kusalananda I think your solution is working. Testing a few more scenarios now. Thank you much. I dont know if I can accept a sub comment as an answer.

– JuanD
yesterday













@Kusalananda: Either should work, I tend to use the () construct when I'm using extglobs just because it's obvious it's not "normal", when a block of code is copied from one script to another, and I use the @(A|B|C).construct quite a bit.so it's "similar' in my mind.

– XrXca
yesterday





@Kusalananda: Either should work, I tend to use the () construct when I'm using extglobs just because it's obvious it's not "normal", when a block of code is copied from one script to another, and I use the @(A|B|C).construct quite a bit.so it's "similar' in my mind.

– XrXca
yesterday













@XrXca I'm just looking at the code and noticing that the only thing the script is using bash for (and not /bin/sh) is that single array. Changing it to set -- patterns would allow it to run under /bin/sh (the loop would loop over "$@" instead). My personal preference is to use /bin/sh, which is why I commented the way I did. Apart from that, you may well be right.

– Kusalananda
yesterday






@XrXca I'm just looking at the code and noticing that the only thing the script is using bash for (and not /bin/sh) is that single array. Changing it to set -- patterns would allow it to run under /bin/sh (the loop would loop over "$@" instead). My personal preference is to use /bin/sh, which is why I commented the way I did. Apart from that, you may well be right.

– Kusalananda
yesterday


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512148%2fbash-array-with-folder-paths-and-wildcards%23new-answer', 'question_page');

);

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







-bash, shell, shell-script, variable, wildcards

Popular posts from this blog

Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

Frič See also Navigation menuinternal link

Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant