background preloader

Bash

Facebook Twitter

Learn Linux, 101: Manage shared libraries. Overview In this article, learn to find and load the shared libraries that your Linux programs need. Learn to: Determine which libraries a program needsKnow how the system finds shared librariesLoad shared libraries This article helps you prepare for Objective 102.3 in Topic 102 of the Linux Professional Institute's Junior Level Administration (LPIC-1) exam 101. The objective has a weight of 1. Prerequisites To get the most from the articles in this series, you should have a basic knowledge of Linux and a working Linux system on which you can practice the commands covered in this article. Back to top Static and dynamic linking Linux systems have two types of executable programs: Statically linked executables contain all the library functions that they need to execute; all library functions are linked into the executable.

An interesting example on many Linux systems is the ln command (/bin/ln), which creates links between files, either hard links or soft (or symbolic) links. Listing 1. Bash One-Liners :: bashoneliners.com. How to pass arguments to a Bash-script. You can write a bash script such that it receives arguments specified when the script is called from the command line. This method is used when a script has to perform a slightly different function depending on the values of input parameters (the arguments). For example, you may have a script called "stats.sh" that performs a particular operation on a file, such as counting its words. If you want to be able to use that script on many files, it is best to pass the file name as an argument, so that you can use the same script for all the files to be processed.

For example, if the name of the file to be processed is "songlist", you would enter the following command line: sh stats.sh songlist Arguments are accessed inside a script using the variables $1, $2, $3, etc., where $1 refers to the first argument, $2 to the second argument, and so on. FILE1=$1 wc $FILE1 If you have a variable number of arguments, you can use the "$@" variable, which is an array of all the input parameters. The awk programming language. Awk is a programming language that gets its name from the 3 people who invented it (Aho, Weinberger, and Kernighan). Because it was developed on a Unix operating system, its name is usually printed in lower-case ("awk") instead of capitalized ("Awk"). awk is distributed as free software, meaning that you don't have to pay anything for it and you can get the source code to build awk yourself It's not an "I can do anything" programming language like C++ or VisualBasic, although it can do a lot. awk excels at handling text and data files, the kind that are created in Notepad or (for example) HTML files.

You wouldn't use awk to modify a Microsoft Word document or an Excel spreadsheet. However, if you take the Word document and Save As "Text Only" or if you take the Excel spreadsheet and Save As tab-delimited (*.txt) or comma-delimited (*.csv) output files, then awk could do a good job at handling them. I like awk because it's concise. Awk 1 yourfile awk1line.txt - one-line scripts for awk. Sed, the stream editor. Find here the sed FAQ (Frequently Asked Questions) file, some one-line sed scripts, and a brief introduction to sed.

I suggest several "flavors" of sed for DOS/Windows users. What is sed? Originally designed for Unix, sed has been available for DOS and other operating systems for many years. Sed is a non-interactive editor that works from a command line; it is not a Windows application with icons or a menu bar. What does it do? Sed changes text: deleting, adding, inserting, substituting. Sed changes blocks of text "on the fly" by using a pre-written list of commands. "Hey," you might ask. Not like this. How it works: You feed sed a script of editing commands (like, "change every line that begins with a colon to such-and-such") and sed sends the altered text to the screen. This sample will change "black" to "white" throughout your file: sed "s/black/white/g" input.txt >output.txt sed -f myscript.sed input.txt >output.txt Setting up an environment for sed.