I'm learning to write bash scripts and I have a script that goes like this:
#!/bin/bash
log_file="user_data.log"
exec > $log_file 2>&1
# Update list of available packages
sudo apt update
# Install required packages
sudo apt install docker.io docker-compose git nginx certbot python3-certbot-nginx -y
I get stdin and stderr redirected to user_data.log, however i would like to see commands (e.g. sudo apt update) in the same logfile. How do I do this?
Is there a better way to achieving this (without sh script.sh > somewhere)?
thank you so much for your help.
As commented by @KamilCuk, I needed to add this at the start of the script: