Hacker News new | past | comments | ask | show | jobs | submit login

Brace expansion won't work if you need to make edits in multiple places.



Well, it could work if we have a function to pick off the first and last combination from the Cartesian product, haha.

We define:

  # print first and last argument
  fl() {
   local a=("$@");
   printf "%s %s\n" "${a[0]}" "${a[${#a[@]} - 1]}"
  }
Now:

  $ fl {a,b}--{c,d}--{foo,bar}--{x,y}--{m,n}
  a--c--foo--x--m b--d--bar--y--n
We can use this using command substitution, or the old backticks:

  $ mv $(fl path/{from,to}/subdir/{foo,bar}.png)
There we go; edits in multiple places.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: