LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script interpreting - comma (https://www.linuxquestions.org/questions/linux-newbie-8/script-interpreting-comma-4175583202/)

vincix 06-27-2016 06:09 PM

script interpreting - comma
 
I'm trying to understand how the following works exactly:

for file in /{,usr/}bin/*calc
# ^ Find all executable files ending in "calc"
#+ in /bin and /usr/bin directories.


Does the comma simply mean that the word 'usr/' is optional?

allend 06-27-2016 06:28 PM

That is an example of brace expansion (see 'man bash' for further details). /{,usr/}bin/*.calc is expanded to /bin/*.calc and /usr/bin/*.calc

vincix 06-28-2016 02:23 PM

Not of much help, really. I know the idea behind brace expansion, but I don't understand the role of the comma there. Your explanation simply repeated what I've already pasted in my first post.

Does the comma refer to what is before it, i.e. nothing? So could it be that it's either nothing, or "usr/"?

suicidaleggroll 06-28-2016 02:52 PM

Yes

{a,b} expands to a and b
{,b} expands to <nothing> and b

vincix 06-28-2016 02:53 PM

Great. Thanks :)


All times are GMT -5. The time now is 02:05 AM.