Here are two ways on who to redirect both standard output and standard error to same file in bash. First the official a recommended way:

printf '%s\n%\n' "Hello bash" > FILE 2>&1

now easier unofficial way:

Sometimes it is needed to check what user is executing the bash script and whether the user supplied all required arguments:

This Perl programming tutorial is a great scripting guide to help you fully understand Perl script. Find Perl tutorials and programming examples to master your knowledge of Perl Scripting.

Hello World Bash Shell Script

Attention: For more verbose and beginner style Bash scripting tutorial visit our Bash Scripting Tutorial for Beginners

First you need to find out where is your bash interpreter located. Enter the following into your command line:

$ which bash

This article provides few simple scripts to scan and monitor network using combination of bash and ping command. Obviously, these scripts are no match to a full monitoring dedicated software like nagios but they could be useful for a small home brand networks, where implementing sophisticated monitoring system can become an overhead.

Scan network subnet

In this example the bash script will scan network for hosts attached to an IP address 10.1.1.1 - 255. The script will print message Node with IP: IP-address is up if ping command was successful. Feel free to modify the script to scan your hosts range.

When writing a bash scripts most of us by default use echo command as means to print to standard output stream. echo is easy to use and mostly it fits our needs without any problem. However, with simplicity very often comes limitation. This is also the case with echo command. Formatting an echo command output can be a nightmare and very often impossible task to do.

The solution to this can be a good old friend of all C/C++ the “printf” tool. printf can be just as easily implemented into a bash script is it is used with C/C++ programs. This article describes some basics of printf along with practical examples:

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: