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

FFmpeg's Leader Resigns, Hopes To Make Libav Developers Come Back

Michael Niedermayer, the leader of the FFmpeg project for the past eleven years, has made a surprise announcement today: he's resigning as its leader. Niedermayer is resigning as he no longer feels he's the best leader for FFmpeg, given the current Libav fork still persisting even after Debian dropped Libav and is returning to FFmpeg. Read more

30 Sys Admins to Follow on SysAdmin Day

Systems administrators: They keep our high-tech world up and running. From capacity planning, to 3 a.m. phone calls, to retiring that 10-year-old server that uses more power than your whole house, sys admins do it all. Open source communities would not be able to thrive without the networks, services, and tools that allow for communication and collaboration, and sys admins are the ones who work thanklessly year-round to keep them going. July 31 is System Administrator Appreciation Day, a day for all of us to express our undying gratitude for sys admins. Sure, you could buy your favorite sys admin cake and ice cream, or perhaps a nice gift card. You could even go as far as not breaking the server for just one day. You also can follow these 30 sys admins. Read more

The Document Foundation Released LibreOffice 4.4.5 With Bug Fixes


The Document Foundation Released LibreOffice 4.4.5 With Bug Fixes

The document foundation released another update LibreOffice 4.4.5 which contains 80+ bug fixes over the previous release. LibreOffice is one of the most popular Office app that is also very active. Regular releases makes it more stable and feature-rich. According to the team LibreOffice 4.4.5 replaces LibreOffice 4.3.7 as "still" version for more conservative users and enterprise deployment. Install this update in Ubuntu/Linux Mint or other derivatives to get bug fixes. 

Read At LinuxAndUbuntu

Today in Techrights