Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 267
Source Link
Audun Olsen
  • 217
  • 1
  • 2
  • 7

printf outputs rows, not columns

I have two arrays, which I want to print out in two separate columns from a single printf call. The following:

printf "%-${padding}s→  %s\n" "${lnFrom[@]}" "${lnTo[@]}"

Outputs:

dotfiles/git/gitconfig         →  dotfiles/hyper/hyper.css
dotfiles/hyper/hyper.js        →  dotfiles/nvim/nvimrc
dotfiles/nvim/warm_nature.vim  →  dotfiles/zsh/zshrc
~/.gitconfig                   →  ~/.hyper.css
~/.hyper.js                    →  ~/.nvimrc
~/.vim/colors/warm_nature.vim  →  ~/.zshrc

The three first lines are represent the lnFrom array, and the three last lnTo, they should be on their respective columns.

(padding in the printf statement is just a variable containing the length of the longtest string in lnFrom array)

Thoughts on how to fix this while keeping the single printf call? (not introducing any loops)