This was given as an exercise in my analysis textbook. The textbook drops hints here and there but anyways here's my attempt:
Suppose that $f$ is continuous but not bounded above on $[a,b]$ and that (without loss of generality), $f(a)=0$. For each $n\in \mathbb{N}$, we define $S_n =\left\{ x \in [a,b] \colon f(x) \ge n \right\}$. Because we are assuming $f$ is not bounded below, each $S_n \ne \varnothing$. Let $x_n = \inf S_n$. We claim that $f(x_n) = n$.
Let $n \in \mathbb{N}$ be fixed. Since, $x_n$ is the greatest lower bound of $S_n$, for each $m\in \mathbb{N}$, there is $x_{m}^{\prime }$ such that $x_n \le x_{m}^{\prime } < \min \left\{ b, x_n + \frac{1}{m} \right\}$. We now note that $f(x_{m}^{\prime }) \ge n$ for all $m\in \mathbb{N}$ and because $S_n \subseteq [a,b]$, we have $\inf [a,b] =a \le \inf S_n = x_n \le b=\sup [a,b]$. Clearly, $(x_{m}^{\prime })$ is sequence in $[a,b]$ converging to $x_n \in [a,b]$. Thus, by the continuity of $f$, we have that $\lim f(x_{m}^{\prime }) = f(x_n) \le n$. Now if $f(x_n) > n$ then $n > 0 = f(a)$ and thus, by the intermediate value theorem, there is a point $c \in (a, x_n)$ such that $f(c)=n$. Thus, $c \in S_n$ but this contradicts the fact that $x_n$ is a lower bound for $S_n$. Thus, it must be that $f(x_n) =n$.
Now, we will show that $(x_n)$ is monotonic increasing and thus convergent (since it is bounded above by $b$). Suppose that there is $n \in \mathbb{N}$ such that $x_{n+1} < x_n $. Then it must be that $x_{n+1} \not \in S_n$. (If not, then $x_n$ would no longer be an lower bound for $S_n$) It follows that $f(x_{n+1}) < n$. By the previous claim, we have $n+1 < n$ which is a contradiction. Thus, it must be that $x_{n+1} \ge x_{n}$ for all $n \in \mathbb{N}$. And thus, $(x_n)$ must converge to some $c\in [a,b]$.
Because $(x_n)$ is a sequence in $[a,b]$ converging to $c$, by the continuity of $f$, we have $\lim f(x_n) = f(c)$. But also from our claim, we have that $\lim f(x_n) = +\infty$ and thus a contradiction. It must be that $f$ is bounded on $[a,b]$.
Is my proof correct? Any suggestions to my writing? Can it be made shorter? I know it's extremely long, thanks for reading it.
Your proof is fine. Here is the essence of it: suppose $f$ is unbounded. Then, $S=\left \{ (-\infty, f(x)):x\in [a,b] \right \}$ is a cover of $f([a,b])$:
let $x\in [a,b]$. Since $f$ is unbounded, there is a $y\in [a,b]$ such that $f(y)>f(x), $ and therefore $f(x)\in (-\infty, f(y)).$
Since $f([a,b])$ is compact, we can pass from $S$ to a finite subcover $S'=\left \{ (-\infty, f(x_i)):x\in [a,b]; 1\le i\le n \right \}.$ But then $\max_{1\le i\le n} \left \{ f(x_i)) \right \}$ is not covered by $S'$, which is a contradiction.