Create Your Own Simple Bash Command from Complex Command in Linux

Arumusutakimu
2 min readJul 9, 2022

--

Hi! In this article, I’m going to show you how to create a simple command from complex command in Linux by creating bash executable program that contains the complex command.

E.x. : command for converting odt document to pdf document. It takes kinda much words.
Using bash executable program named ‘kepdf’ for doing same thing.

As you can see, in first image looks that you must type long command (‘libreoffice — convert-to…and so on.’) for converting. But, in second image, only type ‘kepdf’ for doing same thing.

In here, ‘kepdf’ is bash executable program that I’ve created and I put it into /usr/bin/ directory . If we see inside of ‘kepdf’, it contains plain texts with bash format as shown below :

  • #!/bin/bash → is a flag for telling that the file is bash program
  • libreoffice --convert-to pdf “$1” → is main program that will be execute
  • “$1” → for passing an argument. This depend on your program need. If the command needs arguments for running, you add “$1” “$2” “$3” and so on. The numbers become markers of the order in which the arguments will be passed.

Example : creating ‘unblockpdf’ bash program for unblocking blocked pdf document by password.

The original command is :

qpdf --password=[password] --decrypt [blocked_pdf_name] [output]

Open your terminal and create bash executable program :

nano unblockpdf

Then write the following command in it :

#!/bin/bash
qpdf --password=”$2" --decrypt “$1” “$3”

(NB : Remember! The numbers become markers of the order in which the arguments will be passed.)

Save it and exit : Ctrl + x then type ‘y’ then Enter

Make the program executable : sudo chmod +x unblockpdf

Move it into /usr/bin/ directory : sudo mv unblockpdf /usr/bin/

Now, you can run this command from wherever path by typing unblockpdf …

Thank you.

--

--

No responses yet