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

Samsung Galaxy Tab S2 Reviewed: The Ultimate Android Tablet

Both models of the Galaxy Tab S2 are impressive. Of the two, I’m partial to the 8-inch Tab because its size is perfect for what I like to do with a tablet, like reading comics and watching movies. The question now is, should you buy a Tab S2 instead of the iPad? Read more

Nextbit’s Robin Is An Android Smartphone That Taps The Cloud For Bonus Smarts

After weeks of teasing out little details on Twitter, Nextbit has finally spilled the beans on what they’ve been working: Robin, a “cloud-first” Android smartphone. So what does “cloud-first” mean? At least initially (the company suggests that the cloud integration will only get deeper in time), it means smart, automated offloading of your photos, videos, and apps to free up the local storage space on your device. Robin has 32GB of storage built in. As you fill this, it’ll automatically back up your photos and apps to a private 100GB box on their cloud server. Read more

Xiaomi said to release notebook in 2016 with help from Inventec and Foxconn

The sources believe Xiaomi will likely release a 15-inch notebook as it is the mainstream size in China and will adopt Linux operating system. The notebook is estimated to be priced at CNY2,999 (US$471) and will heap pressure on competitors' simliar products priced between CNY4,000-6,000. Read more Also: Xiaomi GNU/Linux Notebook In 2016

First RC Build of Tiny Core Linux 6.4 Adds a New ASCII Penguin in MOTD

Robert Shingledecker, the creator, maintainer, and lead developer of the Tiny Core project announced earlier today, September 1, the immediate availability for download and testing of the first Release Candidate (RC) build of Tiny Core Linux 6.4. Read more