I put together a bunch of alias commands in a folder. Mainly ssh, so instead of having to type...
ssh [user]@[server]
...ten times a day, I can just type...
server
...and the alias script fires. The script is simply the command...
ssh [user]@[server]
This is all working fine, but I was wondering if there was a way in Bash where instead of firing the ssh command quietly, it would display the command that is being executed?
Explanation: echo will print the command but not execute it. Just omit it to actually execute the command.
The echo command is used to display a line of text that is passed in as an argument. This is a bash command that is mostly used in shell scripts to output status to the screen or to a file.
You can debug the script with -x
, which will echo the commands and arguments.
bash -x script.sh
You can do this for specific portions of the file, too (from section 2.3.2 linked above):
set -x # activate debugging from here ssh [email protected] ... set +x # stop debugging from here
The output from -x
might be a bit too verbose for what you're looking for, though, since it's meant for debugging (and not logging).
You might be better off just writing out your own echo
statements - that'd give you full control over the output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With