I know this sounds strange, but here is the thing. I have a docker container, that hosts a database. And I have a script, that tries to execute a set a patches over it one by one. Now, the script does not know the database port (since each time the container binds to a different port). So here is the beginning of the script:
#!bin/bash
echo "Calculating the port..."
port=$(docker-compose ps | grep database-docker | sed "s/.*://g" | sed "s/\-.*//")
echo "Port is $port"
Basically it's supposed to react on the output of docker-compose ps, that outputs something like this:
Name Command State Ports
wildfly_database-docker_1 docker-entrypoint.sh mysqld Up 0.0.0.0:32768->3306/tcp
But, here is the thing. If my terminal window is small, this script does not work, the port variable is empty. If I expand terminal window at full screen, it works fine, and does what I need. I guess that's because the output in the first case is broken in several lines, and it cannot be parsed correctly.
So, how to make bash script work independently of the window size?
UPD. I found the solution thanks to the comment. It seems like this is an issue of docker-compose. But after I change it to this line
port=$(docker ps | grep database-docker | sed "s/.*://g" | sed "s/\-.*//")
Everything works fine. Docker itself is not affected by the terminal size.