Language Selection

English French German Italian Portuguese Spanish

10 Tips for Writing Efficient Bash Scripts

Filed under

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

Default Local DNS Resolver Integration Proposed for Fedora 24 Linux

Fedora Project's Platform and Program Manager, Mr. Jan Kurik, published another feature proposal for the upcoming Fedora 24 Linux operating system, the implementation of a default local DNS resolver. Read more

Gorgeous Deepin 15 Linux OS Gets a Second Alpha Build with Many Features

The developers of the Deepin Linux distribution designed from the ground-up to provide users with a beautiful, secure, stable, user-friendly, safe and reliable computer operating system have announced the release of Deepin 15 Alpha 2. Read more

Mesa 11.1 RC2 Brings Dozens Of Fixes

It's coming a few days late, but Mesa 11.1 Release Candidate 2 was officially released today. Mesa 11.1 when released later in December will have many new features but doesn't bump the overall OpenGL version support. Now being past the Mesa Git branching, Mesa 11.1-RC2 is just about bug/regression fixing. Read more