1

I have a file containing "lines" of text, for now only two lines. I need to create a reversed array of these lines - FIFO style.

Using "readarray" in this fashion works fine:

readarray -t FileArray < "$PWD$DEBUG_DIR$DEBUG_MENU"

When I attempt to "reverse" the file I get gibberish:

readarray -t FileArray < tac "$PWD$DEBUG_DIR$DEBUG_MENU"

I am still learning about substitution and it is obvious I am not using the tac command correctly. I did try different "syntax" without success.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227

1 Answers1

2

Input redirection (as in cat < file) means the shell is opening the input file and writes its contents to the standard input of another process. It is not possible to just put a command after <.

But you can use Process Substitution to create a file descriptor from the output of the command using the following syntax:

<(some_command)

This is similar to using output from a command like a variable using $(some_command).


Try this:

readarray -t FileArray < <(tac "$PWD$DEBUG_DIR$DEBUG_MENU")
pLumo
  • 22,231
  • 2
  • 41
  • 66
  • Thanks works as advertized. I guess ti need to atke a closer look at file desrtiptors. –  Sep 10 '18 at 14:01
  • Not sure what is going on here , but this has been solved. –  Sep 11 '18 at 22:18