I have the following bash script, inside that statement, it has several commands with few echo commands. Is it possible to get the only last echo statement as return statement and ignore all other echo commands?
#!/bin/bash function statement(){ echo "This is the first statement" echo "This is the second statement" # do something else echo "The result is ok" # I want to display only this in my output. } last_echo=$(echo $(statement)) echo "${last_echo}"
This will output every statement:
This is the first statement This is the second statement The result is ok
Expected output:
The result is ok
Use tail to extract just the last line.
tail
result=$(statement | tail -n 1)
2.1m questions
2.1m answers
60 comments
57.0k users