Good day dear shell coder, hello again. Almost new year over here. How about you ?

Preface

One of my issue I found when I try to port pacaur is that it use a BASH configuration as a part of source.

. source /etc/makepkg.conf

And the fact about this config that, BASH is not compatible with ZSH in context of clobbering opt/*/{doc,gtk-doc}.

DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc})

You can have a look at the difference between BASH and ZSH in figure below.

BASH and ZSH compatibility

Here is step by step.

  • First, the issue itself: parsing BASH, still in BASH

  • Second, make it an array in BASH

  • Third, make it an array in Z Shell


Subshell

I asked in stackoverflow, and somebody is pointing me to the right direction, using bash -c.

 
#!/usr/bin/env bash

TEXT_DIRS='usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}'
bash -c echo\ $TEXT_DIRS

And the output is:

 
usr/doc usr/gtk-doc usr/share/doc usr/share/gtk-doc usr/local/doc usr/local/gtk-doc usr/local/share/doc usr/local/share/gtk-doc

Now you can put it in variable using command substitution.

 
#!/usr/bin/env bash

TEXT_DIRS='usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}'
DIRS=$(bash -c echo\ $TEXT_DIRS)

In BASH

 
#!/usr/bin/env bash

TEXT_DIRS='usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}'

DIRS=$(bash -c echo\ $TEXT_DIRS)
echo -e "${DIRS[@]} \n"

DIRS_ARRAY=($DIRS)
for DIR in "${DIRS_ARRAY[@]}"; do 
  echo "$DIR"
done

And the output is:

Array from String BASH

 
usr/doc usr/gtk-doc usr/share/doc usr/share/gtk-doc usr/local/doc usr/local/gtk-doc usr/local/share/doc usr/local/share/gtk-doc 

usr/doc
usr/gtk-doc
usr/share/doc
usr/share/gtk-doc
usr/local/doc
usr/local/gtk-doc
usr/local/share/doc
usr/local/share/gtk-doc

In ZSH

 
#!/usr/bin/env zsh

TEXT_DIRS='usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}'

DIRS=$(bash -c echo\ $TEXT_DIRS)
DIRS_ARRAY=("${(@s/ /)DIRS}") 
for DIR in "${DIRS_ARRAY[@]}"; do 
  echo "$DIR"
done

And the output is:

Array from String ZSH

 
usr/doc
usr/gtk-doc
usr/share/doc
usr/share/gtk-doc
usr/local/doc
usr/local/gtk-doc
usr/local/share/doc
usr/local/share/gtk-doc
opt/*/doc
opt/*/gtk-doc

I think this is enough for today. Good luck my friend. Have some fun with your shell.

Thank you for reading.