I was working my way through a primer on Shell (Bash) Scripting and noticed the manpage of mkdir
describes a verbose option which displays a message when a directory is created:
-v, --verbose print a message for each created directory
It seems mkdir -v
has a pre-defined message it prints. Is there a way to print a custom message? Is there a way to permanently set a custom message instead of the default message?
You can create a script like this:
#/bin/bash
/bin/mkdir "$@" |sed -e"s/mkdir: created directory /$USER created folder /"
Then run that script rather than mkdir.
Modify that script for each message you want to change by adding an additional -e"s/x/y" to the sed.
If you insist on it being named mkdir, then you can put it in your search path before mkdir.
I would not recommend naming it mkdir. You will only cause yourself grief for other scripts that call mkdir
From the source code for mkdir.c
, this is the section that deals with the -v
option:
case 'v': /* --verbose */
options.created_directory_format = _("created directory %s");
break;
As you can see, the string that is used is hard-coded into the source. To permanently change the message to a custom message, one can modify this section of the source code and recompile mkdir
.
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