fork(1) download
  1. #!/bin/bash
  2.  
  3. subsequences () {
  4. local array=("$@")
  5. local this=${array[0]}
  6. local tail
  7. echo "$this"
  8. [ "${#array[@]}" -eq 1 ] && return
  9. subsequences "${array[@]:1}" |
  10. while IFS='' read -r tail; do
  11. printf '%s && %s\n' "$this" "$tail"
  12. echo "$tail"
  13. done
  14. }
  15.  
  16. subsequences fire water air
  17.  
  18. # Works with spaces too
  19. subsequences "one two" "three four"
  20.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
fire
fire && water
water
fire && water && air
water && air
fire && air
air
one two
one two && three four
three four