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

Why Android's Winning The Battle Right Now

Without a doubt, the key technological revolution of our time has been the rise of mobile computing. With iOS and Android leading the charge, the way people communicate has been transformed. Of course the most significant competition in the space is the one between the two dominant mobile platforms: Google and Apple. Together, they make up the lion’s share of the mobile market. The fierce competition between the two has been the driving force behind the incredible pace of development and innovation the market has seen. Read more

Linux Kernel Source Code of BQ Aquaris E4.5 Ubuntu Edition Published on GitHub

Some of you might be aware of the fact that about a week ago, on March 18, Carsten Munk, Chief Research Engineer at Jolla, published an interesting article on his blog, where he claimed that BQ is not offering a GPL license for the Linux kernel that powers the BQ Aquaris E4.5 Ubuntu Edition device. Read more

Google makes deploying software on its cloud a trivial task

Google is offering a new incentive for using its Google Compute Engine. With Google Cloud Launcher, you can launch more than 120 popular open-source packages. Read more

Linux Kernel 3.19.3 Arrives with ARM, ARM64, and IPv6 Fixes, Many Updated Drivers

Greg Kroah-Hartman has announced today, March 26, the immediate availability for download of the third maintenance releases for Linux 3.19 kernel, along with Linux kernels 3.14.37 LTS and 3.10.37 LTS. Additionally, Linux kernel 3.18.10 LTS has also been announced a couple days ago. Read more