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.

  • Related: Bash - reverse an array – Stéphane Chazelas Sep 10 '18 at 14:36
  • Yes, there are other ways to reverse the file, my question was about how to get the tac results into the array. – user238756 Sep 10 '18 at 15:01
  • note that one of the answers there shows how to use readarray with tac. – Stéphane Chazelas Sep 10 '18 at 15:36

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:


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")
| improve this answer | |
  • Thanks works as advertized. I guess ti need to atke a closer look at file desrtiptors. – user238756 Sep 10 '18 at 14:01
  • Not sure what is going on here , but this has been solved. – user238756 Sep 11 '18 at 22:18

Your Answer

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