facebook youtube pinterest twitter reddit whatsapp instagram

Properly Naming a Bash Scripts

Last week, I wrote a basic intro on bash shell scripting in this guide, we would take a look at how to name a script properly.

Let's get this straight, we mostly do name things abruptly in the real world, but you might want to be careful in a shell world as things aren't that black and white. When naming a script, you should not only give your script a sensible name, but you must also make sure it does not conflict with existing commands.

To give this a quick spin, try entering the following at the command prompt:

type test

You'll receive the following output:

devsrealm@server:~/bin$ type test
test is a shell builtin

The type command tells you what the shell will execute (and where it can be found if it is an external file) for any given command.

As you can see, a command called test already exists, so if you call your script test, it will not run at the shell prompt, as there is an existing one. However, script names often end in .sh; even so, there might be other scripts on your system with the same name as the one you chose.

You can also use which or whereis command to locate where the command is located, so, if I do which testI received /usr/bin/test

So, make sure you do proper checking before naming a script.

 

 

 

Related Post(s)

  • sed (Stream Editor) In Bash Scripting

    Another powerful filter in GNU/Linux is sed (stream editor), which is a program for performing basic editing tasks on the output of another program or on a file. sed or stream editor can be used to p

  • awk In Bash Scripting

    Up until now, we have covered a couple of text processing, from sed to grep to sort, and now we have the big daddy, which is awk. awk (which stands for Aho, Weinberger, and Kernighan - its creators)

  • (Bash Script) Automate Multiple Classicpress & Wordpress Installation + [Caching and SSL]

    If you are tired of using control panels (I am because they are mostly not secure, and most comes loaded with bundles of useless stacks), and want to do everything on the server level, I wrote a menu

  • Returning Values From Functions in (Bash)

    In the guide function in bash, we dive deep in bash functions and we also pass some information into the functions to carry out a certain operation. In this guide, I'll show you how to get informatio

  • Functions in Bash

    Functions are modular building blocks for creating powerful and modular scripts, using function makes it easy to isolate a code since it would be in a single building block, which would be isolated f

  • grep (Regular Expression) In Bash Scripting

    We recently discussed filters in bash scripting, in this guide we would look more into the practical usage of using a filter program, and an example of such a program is grep. grep, in its simplest f