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

Intel Graphics On Ubuntu: GNOME vs. KDE vs. Xfce vs. Unity vs. LXDE

For those wondering how the Intel (U)HD Graphics compare for games and other graphical benchmarks between desktop environments in 2018, here are some fresh benchmarks using GNOME Shell on X.Org/Wayland, KDE Plasma 5, Xfce, Unity 7, and LXDE. Read more

Linux Kernel 4.15 Delayed Until Next Week as Linus Torvalds Announces Ninth RC

It's not every day that you see a ninth Release Candidate in the development cycle of a new Linux kernel branch, but here we go, and we can only blame it on those pesky Meltdown and Spectre security vulnerabilities that affect us all, putting billions of devices at risk of attacks. That, and the fact that things haven't calmed down since last week's eight Release Candidate, which was supposed to be the last for the upcoming series. According to Linus Torvalds, there are still has some networking fixes pending, and there's also a very subtle boot bug that was discovered the other day. Read more Also: Linux 4.15 Goes Further Into Overtime: Linux 4.15-rc9

Review: Ubuntu MATE 17.10

Ubuntu MATE 17.10 is a solid release with a few minor caveats about the Mutiny layout. The Traditional MATE layout is very nice, but Mutiny still needs some work. For users who want the classic GNOME 2 look-and-feel, Ubuntu MATE is an excellent choice. However, Unity users looking for a Unity-like experience should still give Ubuntu MATE with the Mutiny layout a try, but need to be aware that it does have some issues and it won't work exactly like Unity. The Contemporary layout is also an option for Unity users, but is even further removed from the Unity experience than Mutiny is. Read more

Today in Techrights