Skip to main content
added 3 characters in body
Source Link
Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k

With any POSIX-like shell, assuming you want to run the command if $i does not contain a period as your example suggests, you'd write it:

case $i in
  (*.*) ;; # contains "."s, do nothing
  (*) drush "$i" command;;
esac

Note that with $(drush site-alias) being left unquoted, split+glob is performed on it. The splitting, which you want, being done on characters of $IFS (space, tab and newline by default (plus NUL in zsh), and the globbing, which you don't want would turn a /* word for instance into all the non-hidden files or directories in /.

On a GNU system, and with a shell with support for Ksh-style process substitution such as the GNU shell (bash), and assuming that command outputs one site-alias per line, you could do:

xargs -rd '\n' -a <(drush site-alias | grep -vF .) -I@ drush @ command

That has several advantages:

  • no globbing
  • properly splits on newline and newline only regardless of what $IFS happens to contain
  • doesn't store the whole output in memory and starts to run drush commands as soon as drush site-alias starts to output something
  • if any of the drush command fails, the failure will be reflected on xargs's exit status.

Note that the failure of drush site-alias if any is still ignored.

With zsh, you could do:

autoload zargs
site_aliases=( ${(f)"$(drush site-alias)"} ) || exit
zargs -I@ -- ${site_aliases:#*.*} -- drush @ command

Where:

  • we also split on newline only by using the f parameter expansion flag (empty lines are discarded).
  • we handle the failure of drush site-alias (here by exiting the script)
  • ${(M)site_aliases:#*.*} filters out (add a M parameter expansion flag to filter in instead) the elements that contain .
  • like xargs, zargs returns a failure exit status if and of the commands fails.

With any POSIX-like shell, assuming you want to run the command if $i does not contain a period as your example suggests, you'd write it:

case $i in
  (*.*) ;; # contains "."s, do nothing
  (*) drush "$i" command;;
esac

Note that with $(drush site-alias) being left unquoted, split+glob is performed on it. The splitting, which you want, being done on characters of $IFS (space, tab and newline by default (plus NUL in zsh), and the globbing, which you don't want would turn a /* word for instance into all the non-hidden files or directories in /.

On a GNU system, and with a shell with support for Ksh-style process substitution such as the GNU shell (bash), and assuming that command outputs one site-alias per line, you could do:

xargs -rd '\n' -a <(drush site-alias | grep -vF .) -I@ drush @ command

That has several advantages:

  • no globbing
  • properly splits on newline and newline only regardless of what $IFS happens to contain
  • doesn't store the whole output in memory and starts to run drush commands as soon as drush site-alias starts to output something
  • if any of the drush command fails, the failure will be reflected on xargs's exit status.

Note that the failure of drush site-alias if any is ignored.

With zsh, you could do:

autoload zargs
site_aliases=( ${(f)"$(drush site-alias)"} ) || exit
zargs -I@ -- ${site_aliases:#*.*} -- drush @ command

Where:

  • we also split on newline only by using the f parameter expansion flag (empty lines are discarded).
  • we handle the failure of drush site-alias (here by exiting the script)
  • ${(M)site_aliases:#*.*} filters out (add a M parameter expansion flag to filter in instead) the elements that contain .
  • like xargs, zargs returns a failure exit status if and of the commands fails.

With any POSIX-like shell, assuming you want to run the command if $i does not contain a period as your example suggests, you'd write it:

case $i in
  (*.*) ;; # contains "."s, do nothing
  (*) drush "$i" command;;
esac

Note that with $(drush site-alias) being left unquoted, split+glob is performed on it. The splitting, which you want, being done on characters of $IFS (space, tab and newline by default (plus NUL in zsh), and the globbing, which you don't want would turn a /* word for instance into all the non-hidden files or directories in /.

On a GNU system, and with a shell with support for Ksh-style process substitution such as the GNU shell (bash), and assuming that command outputs one site-alias per line, you could do:

xargs -rd '\n' -a <(drush site-alias | grep -vF .) -I@ drush @ command

That has several advantages:

  • no globbing
  • properly splits on newline and newline only regardless of what $IFS happens to contain
  • doesn't store the whole output in memory and starts to run drush commands as soon as drush site-alias starts to output something
  • if any of the drush command fails, the failure will be reflected on xargs's exit status.

Note that the failure of drush site-alias if any is still ignored.

With zsh, you could do:

autoload zargs
site_aliases=( ${(f)"$(drush site-alias)"} ) || exit
zargs -I@ -- ${site_aliases:#*.*} -- drush @ command

Where:

  • we also split on newline only by using the f parameter expansion flag (empty lines are discarded).
  • we handle the failure of drush site-alias (here by exiting the script)
  • ${site_aliases:#*.*} filters out (add a M parameter expansion flag to filter in instead) the elements that contain .
  • like xargs, zargs returns a failure exit status if and of the commands fails.
added 1552 characters in body
Source Link
Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k

With any BournePOSIX-like shell, assuming you want to run the command if $i does not contain a period as your example suggests, you'd write it:

case $i in
  (*.*) ;; # contains "."s, do nothing
  (*) drush "$i" command;;
esac

Note that with $(drush site-alias) being left unquoted, split+glob is performed on it. The splitting, which you want, being done on characters of $IFS (space, tab and newline by default (plus NUL in zsh), and the globbing, which you don't want would turn a /* word for instance into all the non-hidden files or directories in /.

On a GNU system, and with a shell with support for Ksh-style process substitution such as the GNU shell (bash), and assuming that command outputs one site-alias per line, you could do:

xargs -rd '\n' -a <(drush site-alias | grep -FvF .) -I@ drush @ command

That has several advantages:

  • no globbing
  • properly splits on newline and newline only regardless of what $IFS happens to contain
  • doesn't store the whole output in memory and starts to run drush commands as soon as drush site-alias starts to output something
  • if any of the drush command fails, the failure will be reflected on xargs's exit status.

Note that the failure of drush site-alias if any is ignoreignored.

With zsh, you could do:

autoload zargs
site_aliases=( ${(f)"$(drush site-alias)"} ) || exit
zargs -I@ -- ${(M)site_aliases:#*.*} -- drush @ command

Where:

  • we also split on newline only by using the f parameter expansion flag (empty lines are discarded).
  • we handle the failure of drush site-alias (here by exiting the script)
  • ${(M)site_aliases:#*.*} filters inout (withadd a M parameter expansion flag to filter in instead) the elements that contain .
  • like xargs, zargs returns a failure exit status if and of the commands fails.

With any Bourne-like shell, you'd write it:

case $i in
  *.*) drush "$i" command;;
esac

Note that with $(drush site-alias) being left unquoted, split+glob is performed on it. The splitting, which you want, being done on characters of $IFS (space, tab and newline by default (plus NUL in zsh), and the globbing, which you don't want would turn a /* word for instance into all the non-hidden files or directories in /.

On a GNU system, and with a shell with support for Ksh-style process substitution such as the GNU shell (bash), and assuming that command outputs one site-alias per line, you could do:

xargs -rd '\n' -a <(drush site-alias | grep -F .) -I@ drush @ command

That has several advantages:

  • no globbing
  • properly splits on newline and newline only regardless of what $IFS happens to contain
  • doesn't store the whole output in memory and starts to run drush commands as soon as drush site-alias starts to output something
  • if any of the drush command fails, the failure will be reflected on xargs's exit status.

Note that the failure of drush site-alias if any is ignore.

With zsh, you could do:

autoload zargs
site_aliases=( ${(f)"$(drush site-alias)"} ) || exit
zargs -I@ -- ${(M)site_aliases:#*.*} -- drush @ command

Where:

  • we also split on newline only by using the f parameter expansion flag (empty lines are discarded).
  • we handle the failure of drush site-alias (here by exiting the script)
  • ${(M)site_aliases:#*.*} filters in (with M) the elements that contain .
  • like xargs, zargs returns a failure exit status if and of the commands fails.

With any POSIX-like shell, assuming you want to run the command if $i does not contain a period as your example suggests, you'd write it:

case $i in
  (*.*) ;; # contains "."s, do nothing
  (*) drush "$i" command;;
esac

Note that with $(drush site-alias) being left unquoted, split+glob is performed on it. The splitting, which you want, being done on characters of $IFS (space, tab and newline by default (plus NUL in zsh), and the globbing, which you don't want would turn a /* word for instance into all the non-hidden files or directories in /.

On a GNU system, and with a shell with support for Ksh-style process substitution such as the GNU shell (bash), and assuming that command outputs one site-alias per line, you could do:

xargs -rd '\n' -a <(drush site-alias | grep -vF .) -I@ drush @ command

That has several advantages:

  • no globbing
  • properly splits on newline and newline only regardless of what $IFS happens to contain
  • doesn't store the whole output in memory and starts to run drush commands as soon as drush site-alias starts to output something
  • if any of the drush command fails, the failure will be reflected on xargs's exit status.

Note that the failure of drush site-alias if any is ignored.

With zsh, you could do:

autoload zargs
site_aliases=( ${(f)"$(drush site-alias)"} ) || exit
zargs -I@ -- ${site_aliases:#*.*} -- drush @ command

Where:

  • we also split on newline only by using the f parameter expansion flag (empty lines are discarded).
  • we handle the failure of drush site-alias (here by exiting the script)
  • ${(M)site_aliases:#*.*} filters out (add a M parameter expansion flag to filter in instead) the elements that contain .
  • like xargs, zargs returns a failure exit status if and of the commands fails.
added 1552 characters in body
Source Link
Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k

With any Bourne-like shell, you'd write it:

case $i in
  *.*) drush "$i" command;;
esac

Note that with $(drush site-alias) being left unquoted, split+glob is performed on it. The splitting, which you want, being done on characters of $IFS (space, tab and newline by default (plus NUL in zsh), and the globbing, which you don't want would turn a /* word for instance into all the non-hidden files or directories in /.

On a GNU system, and with a shell with support for Ksh-style process substitution such as the GNU shell (bash), and assuming that command outputs one site-alias per line, you could do:

xargs -rd '\n' -a <(drush site-alias | grep -F .) -I@ drush @ command

That has several advantages:

  • no globbing
  • properly splits on newline and newline only regardless of what $IFS happens to contain
  • doesn't store the whole output in memory and starts to run drush commands as soon as drush site-alias starts to output something
  • if any of the drush command fails, the failure will be reflected on xargs's exit status.

Note that the failure of drush site-alias if any is ignore.

With zsh, you could do:

autoload zargs
site_aliases=( ${(f)"$(drush site-alias)"} ) || exit
zargs -I@ -- ${(M)site_aliases:#*.*} -- drush @ command

Where:

  • we also split on newline only by using the f parameter expansion flag (empty lines are discarded).
  • we handle the failure of drush site-alias (here by exiting the script)
  • ${(M)site_aliases:#*.*} filters in (with M) the elements that contain .
  • like xargs, zargs returns a failure exit status if and of the commands fails.

With any Bourne-like shell, you'd write it:

case $i in
  *.*) drush "$i" command;;
esac

With any Bourne-like shell, you'd write it:

case $i in
  *.*) drush "$i" command;;
esac

Note that with $(drush site-alias) being left unquoted, split+glob is performed on it. The splitting, which you want, being done on characters of $IFS (space, tab and newline by default (plus NUL in zsh), and the globbing, which you don't want would turn a /* word for instance into all the non-hidden files or directories in /.

On a GNU system, and with a shell with support for Ksh-style process substitution such as the GNU shell (bash), and assuming that command outputs one site-alias per line, you could do:

xargs -rd '\n' -a <(drush site-alias | grep -F .) -I@ drush @ command

That has several advantages:

  • no globbing
  • properly splits on newline and newline only regardless of what $IFS happens to contain
  • doesn't store the whole output in memory and starts to run drush commands as soon as drush site-alias starts to output something
  • if any of the drush command fails, the failure will be reflected on xargs's exit status.

Note that the failure of drush site-alias if any is ignore.

With zsh, you could do:

autoload zargs
site_aliases=( ${(f)"$(drush site-alias)"} ) || exit
zargs -I@ -- ${(M)site_aliases:#*.*} -- drush @ command

Where:

  • we also split on newline only by using the f parameter expansion flag (empty lines are discarded).
  • we handle the failure of drush site-alias (here by exiting the script)
  • ${(M)site_aliases:#*.*} filters in (with M) the elements that contain .
  • like xargs, zargs returns a failure exit status if and of the commands fails.
Source Link
Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k
Loading