I would like to create a new .wc command.
1 Answer
With the exception of shell builtins, commands are just programs. This means your question reduces to, "How do I write a program?"
(Or, "How do I write a script?" which amounts to the same thing, since a script is just another type of program. The distinction between scripting and programming is not important to get into here.)
wc
is a good example, because it is not a shell builtin. It is just another program on the system, typically installed in /usr/bin/wc
or /bin/wc
, depending on the OS.
In order to make your new command behave like the existing ones on the system, the program implementing it has to be installed somewhere in the PATH
. It is common on Linux distributions to put $HOME/bin
into the user's PATH
if the directory is present on login. If you want the command to be available to all users on the system, you probably want to put it somewhere else, like /usr/local/bin
.
wc
command already has command line options to count lines and characters as well as words