Reputation: 6064
I'm writing a script using verbose mode but I'd like to set a prefix to the command outputs (mainly to make the output look nicer).
For example, the script:
#!/bin/bash -v
pwd
hostname
This will give the output:
pwd
/home/username
hostname
myawesomehost
But I'd like the output (specifically with the $
sign):
$ pwd
/home/username
$ hostname
myawesomehost
Is there a way to set a prefix for the verbose output like this?
Upvotes: 9
Views: 1399
Reputation: 785306
You can use PS4
with set -x
(enable trace):
#!/bin/bash
# prompt for trace commands
PS4='$ '
# enable trace
set -x
# remaining script
pwd
hostname
This will produce output as:
$ pwd
/home/username
$ hostname
myawesomehost
Upvotes: 7