loops - bash How to declare and iterate over pairs of values where values may contain spaces (two dimensional array) -


1) declaration

i have pairs of, example, directories. pairs contain spaces (and/or other inconveniences periods or special chars. ext4 supports let say.)

'/foo/dolor sit/amet.elit'         '/bar/accumsan/luctus massa.nec' '/baz/sagittis. fusce/vitae.dolor' '/bam/nunc aliquetjusto.metus' 

i want write bash script these pairs hard-coded/constants.

i highly prefer declaring strings within delimiter or such not need arbitrary string preprocessed (eg don't want add escapes on literal whitespaces if possible)


2) iteration

with declared pairs of strings, wish enter loop both strings available in 1 iteration separate variables, e.g. $left , $right.

likely uses being simple file operations copy, move, link, diff.


notes:

  • the "height" of array should allow many many pairs.
  • if declaration , iteration can support wider-than-2 2d arrays please note how extend desired with.
  • if bash has "array" specific datatype, use not mandatory question/answer. iterable 2-dimensional declaration , iteration sufficient.

you might use associative array (bash 4 or later):

declare -a arr arr['/foo/dolor sit/amet.elit']='/bar/accumsan/luctus massa.nec' arr['/baz/sagittis. fusce/vitae.dolor']='/bam/nunc aliquetjusto.metus'  left in "${!arr[@]}";     right=${arr["$left"]}     ... done 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -