DOC PREVIEW
UI CS 270 - Aliases

This preview shows page 1-2-23-24 out of 24 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Aliases Shell Command: alias [-p] [word[=string]]If you alias a new command word equal to string, then when you type the command word the string will be used in its placealias prints out all aliases definedput your aliases in your .bashrc file (why?)e.g. alias dir=”ls -al”unalias1History Shell Command: history [-c] [n]Print out the shell's current command history. If a numeric value n is specified, show only the last n entries in the history list. If "-c" is used, clear the history list.2Command Re-execution 3History Substitution^string1^string2^Substitute string2 for string1 in the previous command and executes it.$ lp financial_report_july_2003.txtlp: File not found.$ ^2003^2004^lp financial_report_july_2004.txtrequest id is lwcs-37 (1 file)$ _4Auto-Completion Bash can complete a filename, command name, username or shell variable name To have Bash attempt to complete the current argument of your command, type the TAB character. 5Tilde Substitution 6Command substitution $(command)$ echo there are $(who | wc -l) users on the systemthere are 6 users on the system$ _7Arithmetic+ - Addition, subtraction.++ -- Increment, decrement.* / % Multiplication, division, remainder.** Exponentiation.Shell command: declare -i nameThis form of declare defines the variable name as an integer value8Conditional ExpressionsArithmetic conditional operators<= >= < > Less than or equal to, greater than or equal to, less than, greater than comparisons== != Equal, not equal! Logical NOT&& Logical AND|| Logical OR9Conditional Expressions10$ cat divisors.sh#!/bin/bash#declare -i testval=20declare -i count=2 # start at 2, 1 always workswhile (( $count <= $testval )); do (( result = $testval % $count )) if (( $result == 0 )); then # evenly divisible echo " $testval is evenly divisible by $count" fi (( count++ ))done$ bash divisors.sh 20 is evenly divisible by 2 20 is evenly divisible by 4 20 is evenly divisible by 5 20 is evenly divisible by 10 20 is evenly divisible by 20$ _String Comparisons String conditional operators.-n string True if length of string is non-zero.-z string True if length of string is zero.string1 == string2 True if strings are equal.string1 != string2 True if strings are not equal.11File-Oriented Expressions file-oriented conditional operators (see Figure 6-29)12File-Oriented Expressions $ cat owner.sh#!/bin/bash#if [ -O /etc/passwd ]; then echo "you are the owner of /etc/passwd."else echo "you are NOT the owner of /etc/passwd."fi$ bash owner.shyou are NOT the owner of /etc/passwd.$_13Control Structures case .. in .. esacif .. then .. elif .. then .. else .. fifor .. do .. donewhile/until .. do .. donetrap14case .. in .. esacShell command: casecase word in pattern { | pattern }* ) commands ;; ...esacExecute the commands specified by commands when the value of word matches the pattern specified by pattern. The ")" indicates the end of the list of patterns to match. The ";;" is required to indicate the end of the commands to be executed.15if .. then .. elif .. then .. else .. fiif test1; then commands1;[elif test2; then commands2;][else commands3;]fitest1 is a conditional expression, which, if true, causes the commands specified by commands1 to be executed. If test1 tests false, then if an "elif" structure is present, the next test, test2, is evaluated ("else if"). If test2 evaluates to true, then the commands in commands2 are executed. The "else" construct is used when you always want to run commands after a test evaluated as false.16for .. do .. done Shell command: forfor name in word { word }*do commandsdonePerform commands for each word in list with $name containing the value of the current word.17while/until .. do .. doneIn a while statement, perform commands as long as the expression test evaluates to true. In an until statement, perform commands as long as the expression test evaluates to false (i.e., until test is true).18until testdo commandsdone Shell command: while/untilwhile testdo commandsdonetrapShell command: trap [ [ command ] { signal } +]The trap command instructs the shell to execute command whenever any of the numbered signals signal are received. If several signals are received, they are trapped in numeric order. If a signal value of 0 is specified, then command is executed when the shell terminates. If command is omitted, then the traps of the numbered signals are reset to their original values. If command is an empty string, then the numbered signals are ignored. If trap is executed with no arguments, a list of all the signals and their trap settings is displayed. For more information on signals and their default actions, see Chapter 12, "Systems Programming."19FunctionsBash allows to define functions that can be invoked as shell commandsfunction name{ list of commands} or the keyword function may be omitted:name (){ list of commands.} 20Functionsparameters are accessible based on their positions$ cat func2.sh ...list the script.f (){ echo parameter 1 = $1 # display first parameter. echo parameter list = $* # display entire list.}# main program.f 1 # call with 1 parameter.f cat dog goat # call with 3 parameters.$ sh func2.sh ...execute the script.parameter 1 = 1parameter list = 1parameter 1 = catparameter list = cat dog goat$ _21Functionsreturn [value] return valueexport -f functionname -f option exports functionlocal name[=value] defines variable to be local to current functionbuiltin [command [args]]runs the named shell built-in command, and passes it args if present.22more ...select name [ in {word }+ ]do listdone Directory access and directory stackpushdpopddirs23Job Control jobs [-lrs] display all of the shell’s jobsbg, fg,


View Full Document

UI CS 270 - Aliases

Download Aliases
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Aliases and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Aliases 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?