You can use $USER instead of invoking another program, i.e. $(whoami). Similarly for $PWD. You can also use printf directly to print the date, check man strftime.
The printf command is really powerful and is more than an extension to echo. Note that the way you are using it may cause issues, as it concatenates the format and the variable(s) part:
printf 'FORMAT' $VALUE(S)
Or as an example:
printf 'You are here => %s\n' "$PWD"
You may also want to check out the short notation for the bash built-in test command [[ ]].
You can use
$USER
instead of invoking another program, i.e.$(whoami)
. Similarly for$PWD
. You can also use printf directly to print the date, checkman strftime
.The
printf
command is really powerful and is more than an extension toecho
. Note that the way you are using it may cause issues, as it concatenates the format and the variable(s) part:Or as an example:
You may also want to check out the short notation for the bash built-in test command
[[ ]]
.Recommendations: