Language Selection

English French German Italian Portuguese Spanish

10 Tips for Writing Efficient Bash Scripts

Filed under
HowTos

Bash is the default command line interface for many Linux distributions and a powerful scripting language. Here are some suggestions that will keep your Bash scripts efficient and lean.

1. Avoid Full Paths to Bash Builtins

Bash has many builtins that can be used instead of calling external commands. You should leverage the builtin commands whenever possible since it avoids calling a subcommand from the system.

Since Bash has builtins for some commands found in /bin and /usr/bin (such as echo), avoid using the full path for these commands and the builtin will be used.

# avoid this
/bin/echo "hello"

Use the Bash builtin instead:
echo "hello"

Other bash builtins include: test, read, declare, eval, let pushd and popd. See the Bash man page for a full listing of builtins.

2. Avoid External Commands for Integer Math

More Here




More in Tux Machines

today's leftovers

US Military To Launch Open Source Academy

Open source software, which has become increasingly common throughout the US military from unmanned drones to desktops, has now been enlisted as a career option for military personnel. In September, Camp Shelby Joint Forces Training Center will open a Linux certification academy, marking the first time such a training program has been hosted on a military base. Read more

Video: TedX talk - Richard Stallman

Well, vp9/opus in a webm container have been supported by both Firefox and Google Chrome for several releases now... so enjoy it in your web browser. Read more

Eclipse Luna for Fedora 20

If you are a Fedora Eclipse user, then you're probably saddened since the release of Eclipse Luna (4.4) because you are still using Eclipse Kepler (4.3) on Fedora 20. Well, be saddened no longer because Eclipse Luna is now available for Fedora 20 as a software collection! A software collection is simply a set of RPMs whose contents are isolated from the rest of your system such that they do not modify, overwrite or otherwise conflict with anything in the main Fedora repositories. This allows you install multiple versions of a software stack side-by-side, without them interfering with one another. More can be read about this mechanism on the software collections website. The Eclipse Luna software collection lives in a separate yum repository, which must be configured by clicking on this link to install the release package. Read more