1 / 16

Red Hat Academy Workbook 11

Red Hat Academy Workbook 11. Supplements. Chapter 1: Advanced Shell Scripting . The read command reads input from stdin . The test keyword allows you to make logical tests for branching, looping, etc. Conditional statements in bash are available as if…then…[else…]fi .

walter
Download Presentation

Red Hat Academy Workbook 11

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Red Hat AcademyWorkbook 11 Supplements

  2. Chapter 1: Advanced Shell Scripting  • The read command reads input from stdin. • The test keyword allows you to make logical tests for branching, looping, etc. • Conditional statements in bash are available as if…then…[else…]fi. • Loops can be implemented using for…in…do…done. • Command arguments in bash scripts are available as $1, $2, $3, etc.

  3. The read command in bash • The read command reads one line of text from stdin. • Format: read var1 [var2 …]

  4. Testing conditions • The test keyword can be used to test certain conditions in bash: test condition • Appears usually in the context of an if, while, or for statement.

  5. Example tests

  6. More example tests

  7. Still more example tests

  8. Branches in bash • Branching in bash: If conditionthencommand(s) else command(s)fi

  9. Example script

  10. The for loop in bash • The for loop can be expressed like this: for VICTIM in list do statement(s) done • This will loop through every item in list, with $VICTIM representing each one in turn.

  11. for loop example • Takes the list of files in the current directory, and prints them out with a joyful comment. • Note the `ls`, and the reference to the $PWD environment variable.

  12. Another loop: while • For loops are good for when loops are bounded, i.e. you know how many times to loop. • For unbounded loops, use while instead: while condition do statement(s) done

  13. Accessing command line arguments in bash • The command line can be accessed with the $0 shell variable. • The number of arguments included is represented by the $# shell variable. • Each argument is represented by $1, $2, $3, etc. • The shift command forces each argument to shift down by one place. This is useful when the number of arguments can vary, or is otherwise unknown.

  14. Accessing command line arguments in bash • Sample script prints out the entire command line, then each argument in turn: #!/bin/bash #print out command line:echo $0 #print out the number of arguments: echo Number of arguments: $# #print out each argument, one per line: i=0 while test $1 do i=$(($1+1)) echo argument \#i: $1 shift done

  15. Chapter 2: Character Encoding and Internationalization Where is it??? 

  16. Chapter 3: The RPM Package Manager  • The rpm command is used to add or remove software from your system. • You must have root privileges to add and remove software with rpm. • Anyone can query installed packages, or package files. • Installed packages are maintained in the rpm database. • Queries can be made of the database with the –q switch.

More Related