2

This question is based on similar question at https://askubuntu.com/a/1066404/1069309, but instead of bash, I would like to have similar output in sh

No issue in bash, it work as expected.

wolf@linux:~$ echo $SHELL
/usr/bin/bash
wolf@linux:~$ 
wolf@linux:~$ varA='Aug 01
> Aug 16
> Aug 26'
wolf@linux:~$ 
wolf@linux:~$ varB='04:25
> 03:39
> 10:06'
wolf@linux:~$ 
wolf@linux:~$ echo "$varA $varB"
Aug 01
Aug 16
Aug 26 04:25
03:39
10:06
wolf@linux:~$
wolf@linux:~$ paste <(printf %s "$varA") <(printf %s "$varB")
Aug 01  04:25
Aug 16  03:39
Aug 26  10:06
wolf@linux:~$ 

However, when I try similar command in sh, I'm getting the following error.

wolf@linux:~$ sh
$ 
$ varA='Aug 01
Aug 16
Aug 26'

$ varB='04:25
03:39
10:06'> > 
$ 
$ echo "$varA $varB"
Aug 01
Aug 16
Aug 26 04:25
03:39
10:06
$ 
$ paste <(printf %s "$varA") <(printf %s "$varB")
sh: 22: Syntax error: "(" unexpected
$ 

Is it possible to get similar output in sh?

4
3

If your variables have the same number of lines then you could use the pr command to print standard output into two columns ex.

$ printf '%s\n' "$varA" "$varB" | pr -2 -Ts^I       
Aug 01  04:25
Aug 16  03:39
Aug 26  10:06

where ^I stands for the TAB character (to be consistent with the default separator of the paste command) and may be introduced using key combination Ctrl+V TAB, while -T turns off headers and footers.

1
  • If your shell is bash, you can write -s $'\t' – glenn jackman Jan 19 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.