Tag:
script

Find the exit status of a previous command in Bash

by
on
January 14, 2011

Most programs will return an exit status of 0 if the program was successful, while a non-zero exit status usually indicates an error. You can find the exit status or exit code of the previously executed command by accessing the “$?” shell variable. $ COMMAND $ echo $? Typically when a command terminates on a [...]

Read More
No Comments
bash

Find the parent PID of a Bash Script

by
on
January 9, 2011

For any number of reasons you may want to know the parent process ID of the current Bash script. You can find the parent process of the current Bash script or shell by printing the ‘$PPID‘ shell variable. $ echo $PPID20341

Read More
No Comments
bash

Find the PID of a background child process in Bash

by
on
January 9, 2011

In order to control or monitor background child processes from a shell script you will need to know the PID of the child. Bash stores the PID of the last process executed in the “$!” shell variable. If you start a background process in an interactive shell it will output the PID of the child. [...]

Read More
No Comments
bash

Find the PID of the current Bash script

by
on
January 9, 2011

In many cases you will need to determine the PID of a current Bash script or shell. Bash stores a specific variable that allows you to view the process ID of the current shell “$$‘. You can echo the $$ to print the current PID. $ echo $$23490

Read More
No Comments
bash

Have a Bash script determine it’s own location

by
on
December 15, 2010

At some point it may be helpful to have a BASH script dynamically determine the location of itself when executed from anywhere on the system. The following code will produce the canonicalized absolute pathname of the script, as well as the directory that it resides in. The script first determines if the the first argument [...]

Read More
1 Comment
bash

Multiple line comments in BASH

by
on
September 29, 2010

Comments are done in BASH and most other shells by placing a ‘#’ mark at the beginning of a line. To create a multi-line comment, or to comment out an entire block of code, you can use the following HERE DOCUMENT feature. :

Read More
No Comments
bash

Convert text files within a directory from Windows to Unix format

by
on
January 7, 2009

When a file is saved in Windows and then moved to a Linux system the formatting differences can cause a variety of problems. To effectively use these files you will need to change the format from Windows/DOS to Unix. This conversion occurs by simply removing the Windows carriage return characters. I have explained how to [...]

Read More
1 Comment
bash

Single versus double quotes in BASH

by
on
October 15, 2008

Understanding the difference between double versus single quotes is important when using BASH. Many times you may have seen them being used interchangeably. The basic difference is that variable names will be expanded within double quotes but not within single ones. This example shows the normal output with no quotes. $ echo $USER ryan As [...]

Read More
1 Comment
bash
Copyright 2008-2010 WiredRevolution.com. All rights reserved.