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

Telegram Desktop for Linux Review

Telegram is an instant messaging service that is best known for its mobile implementation, but a desktop app is also available and it's even better than what users might expect. Read more

KaOS 2015.02 Distro Brings a Unique, Pure KDE Plasma 5 Experience - Screenshot Tour

The KaOS development team was proud to announce on February 24 the immediate availability for download of the KaOS 2015.02 Linux kernel-based operating system for personal computers and laptops. This is the first ever release of the KaOS Linux distribution with the next-generation KDE Plasma desktop environment, powered by the latest KDE Frameworks 5 technology. Read more

Snowden's favourite Linux - Tails - rushes sec-fix version to market

The developers want to kill off the previous version, Tails 1.2.3, as soon as possible, with a list of 14 security issues covering everything from the Tor browser and its network security services (NSS) through to a sudo privilege escalation bug. Read more