Bash Scripting Pipe Operator and PostgreSQL

Hey, I’m having trouble with the following code:

TABLE_RESULT=$($PSQL "SELECT * FROM table" )

echo "$TABLE_RESULT" | while read COLUMN1 BAR COLUMN2 BAR COLUMN3
do
  echo "$COLUMN1" # Prints column1_value|column2_value|column3_value
done

I can’t figure out why sometimes the read in the while will identify the different column values and save them into the different variables made to capture them, while other times the whole thing will be saved as a string in the first variable :face_with_raised_eyebrow:

My desired output would be the values in the columns each saved into its corresponding variable.

while IFS=“|” read … without BAR

1 Like

Thanks!! Do you know why it sometimes works and some others it does not?

It works everytime for me…I don’t think i will give you a correct answer to that…I’m currently doing this certificate myself and i’m encountering minimum problems now and then

Happy coding to both of us!