Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate string for bash word-expansion?

Tags:

bash

tree

trie

Bash can generate multiple strings from single, if you use {...,...} syntax. Like here:

$ echo pgdb{200,10{0,1}}
pgdb200 pgdb100 pgdb101

Is there any way to take a list of strings and produce (hopefully shorter) string that, upon processing via bash word expansion will produce original list (not necessarily in original order?

For example, I'd like this tool/algorithm, that given:

  • postgresql
  • mysql
  • postgres
  • miata

would produce (for example): {postgres{ql,},m{iata,ysql}}

I thought about using trie to represent input strings, but can't figure out how to process this trie to build output string.

like image 862
someone Avatar asked Nov 10 '22 13:11

someone


1 Answers

use Compress::BraceExpansion;?

like image 72
pstef Avatar answered Nov 15 '22 05:11

pstef