Tag:
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

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

Command substitution in BASH

by
on
November 7, 2008

BASH has the ability to execute a command string and replace that string with the output of the command. Or to say it another way, the output of a command will replace the command itself. There are 2 ways to accomplish this. The first is to surround the command with backticks or blockquotes. `command` You [...]

Read More
No Comments
bash

Delete a specific line from a text file with sed

by
on
October 26, 2008

At some point you may have the need to remove all lines within a text file that match a certain pattern. Accomplishing this is easy with the sed command. Here is the command format. $ sed -i ‘/PATTERN/ d’ file.txt The ‘-i‘ option allows you to edit the specified file in place. PATTERN is a [...]

Read More
4 Comments
bash

How to correctly use LD_LIBRARY_PATH

by
on
October 22, 2008

The LD_LIBRARY_PATH environment variable contains a colon separated list of paths that the linker uses to resolve library dependencies of ELF executables at run-time. These paths will be given priority over the standard library paths /lib and /usr/lib. The standard paths will still be searched, but only after the list of paths in LD_LIBRARY_PATH has [...]

Read More
5 Comments
system administration

Customize the BASH PS1 command prompt

by
on
October 19, 2008

The PS1 environment controls the appearance of the BASH command line prompt. There are a variety of default prompts but they usually include username, hostname, and working directory. You can easily customize your prompt to display information important to you as well as add color and style formatting. Here we can see the default prompt [...]

Read More
1 Comment
bash

I/O redirection in BASH

by
on
October 16, 2008

One of the best features of the Linux command line is the ability to efficiently direct input and output to and from files and other programs. Every program begins with 3 open file streams. stdin (file descriptor 0) – input from the user, usually keyboard stdout (file descriptor 1) – standard output that is displayed [...]

Read More
No Comments
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.