RH033 Unit6 Using the bash shell
2009-03-19 22:07
274 查看
Objectives 1) Upon completion of this unit, you should be able to: - Use command-line shortcuts - Use command-line expansion - Use history and editing tricks - Use the gnome-terminal Command Line Shortcuts file Globbing 1) Globbing is wildcard expansion - * matches zero or more characters - ? matches any single character - [0-9] matches a rang of numbers - [abc] matches any of the character in the list - [^abc] matches all except the character in the list - Perdefined character classes can be used Command Line Shortcuts The Tab Key 1) Type tab to complete comand lines: - For the command names, it will complete a command name - For an argument, it will complete a file name Command Line Shortcuts History 1) bash stores a history of commands you’ve entered, which can be used to repeate commands 2) use history command to see list of “remembered” commands - !!: repeats last command - !char: repeats last command that started with char - !num: repeats a command by its number in history output More History Tricks 1) Use the up and down keys to scroll through previous commands 2) Type Ctrl-r to search for a command in command history 3) To recall last argument from previous comand: - Esc,. (the escape key followed by a period) - Alt-. (hold down the alt key while press the period) Command Line Expansion the tilde 1) Tilde (~) 2) May refer to your home directory $ cat ~/.bash_profile 3) May refer to another user’s home directory $ ls ~julie/public_html Command Line Expansion Commands and Braces Sets 1) Command Expansion: $() or `` - Print output of e command as an argument to another $ echo “This systems’s name is $(hostname)” This system’s name is server1.exmaple.com 2) Brace Expansion: {} - Shorthand for printing repetitive strings $ echo file{1,3,5} file1 file3 file5 $ rm –f file{1,3,5} Command Editing Tricks 1) Ctrl-a moves to beginning of line 2) Ctrl-e moves to end of line 3) Ctrl-u deletes to beginning of line 4) Ctrl-k deletes to end of line 5) Ctrl-arrow moves left or right by word Gnome-terminal 1) Application –> Accessories –> Terminal 2) Graphical terminal emulator that supports multiple “tabbed” shell - Ctrl-shift-t creates a new tab - Ctrl-PgUp/PgDn switches to next/prev tab - Ctrl-Shift-c copies selected text - Ctrl-Shift-v pastes text to the prompt Scripting Basics 1) Shell scripts are text files that contain a series of commands or statements to be executed. 2) Shell scripts are useful for: - Automating commonly used commands - Performing system administration and troubleshooting - Creating simple applications - Manipulation of text of files Creating Shell Scripts 1) Step 1: Use such as vi to create a text file containing commands - First line contains the magic shebang sequence: #! #!/bin/bash - Comment your scripts! Comments start with a # 2) Step 2: Make the script executable: $ chmod u+x myscript.sh 3) To execute the new script: - Place the script file in a directory in the executable path –OR- - Specify the absolute or relative path to the script the command line Sample Shell Script #!/bin/bash # This script displays some information about your environment echo “Greetings. The date and tiem are $(date)” echo “Your working directory is: $(pwd)” End of Unit6 1) Quetions and Answers 2) Summary - Command expansion: $() - History recall: !string, !num - Inhibition: ‘’, /
相关文章推荐
- RH033 Unit6 Using the bash shell
- RH033 Unit 6 Using the bash Shell
- A quick guide to writing scripts using the bash shell
- 033-Unit 9 Configuring the bash Shell
- RH033 Unit12 Configuring the Bash Shell
- RH033 Unit12 Configuring the Bash Shell
- RH033 Unit 12 Configuring the Bash Shell
- How to access HBase from spark-shell using YARN as the master on CDH 5.3 and Spark 1.2
- the file command and bash shell
- Linux Bash Shell学习(一):开始看书《Learning the bash Shell,3rd》
- HowTo hide Password in shell Scripting using Bash
- The issue about using Git bash for Docker in window
- PowerShell: Using the Interactive Shell
- Using Bash Shell
- Using the NETCONF Protocol over Secure Shell (SSH)
- Using Bash shell scripts for function testing
- Bash/KSH/SH Shell: Find The Length Of a String On a UNIX, Linux, BSD, and OS X
- BASH Shell change the color of my shell prompt under Linux or UNIX
- RH033读书笔记(11)-Lab 12 Configuring the bash Shell
- Bash - the shell (1)