Learning_the_bash_Shell_Third_Edition 1/n

Log in to your system and type 

echo $SHELL

at the prompt. You will see a response containing sh, csh, ksh or b ash.

You need to find out where bash is on your system, i.e., in which directory it’s installed. You might be able to find the location by typing "whereis" bash(especially if you are using the C shell); if that doesn't work, try whence bash , wich bash, or this complex command:*

whereis bash || whence bash || which bash

#

grep bash /etc/passwd | awk -F: '{print $7}' | sort -u

#h, which bash, or this

complex command: *

Another feature of bash’s cd command is the form cd -, which changes to whatever
directory you were in before the current one.

 

Wildcard(通配符) Matches

? ---> Any single character
* ---> Any string of characters(The asterisk),Notice that * can stand for nothing: both *ed and *e* match ed.
[set] --->  Any character in set
[!set] --->   Any character not in set

  

Expression Matches

[abc]           a, b, or c
[.,;]              Period, comma, or semicolon
[-_]             Dash or underscore
[a-c]            a, b, or c

  

#

Expression            Matches

[a-z]                      A ll lowercase letters
[!0-9]                     All non-digits
[0-9!]                     All digits and exclamation point(exclamation point :感叹号)
[a-zA-Z]                 All lower- and uppercase letters
[a-zA-Z0-9_-]         All letters, all digits, underscore, and dash.

  

                 program.[co] and program.[a-z] both match program.c and program.o, but not program.log

To match ! itself, place it after the first character in the set, or precede it with a backslash, as in [\!]

It’s safe to use a range for uppercase letters, lowercase letters, digits, or any subranges thereof (e.g., [f-q], [2-6]). Don’t use ranges on punctuation characters or mixed-case letters: e.g., [a-Z] and [A-z] should not be trusted to include all of the letters and nothing more. The problem is that such ranges are not entirely portable between different types of computers.

Brace Expansion

echo {2..5} you’ll see this expands to 2 3 4 5

Typing echo {d..h} results in the expansion d e f g h

ls *.{c,h,o}  ==  ls *.[cho]

 

Input and Output

The UNIX I/O scheme is based on two dazzlingly simple ideas. First, UNIX file I/O takes the form of arbitrarily long sequences of characters (bytes). In contrast, file systems of older vintage have more complicated I/O schemes (e.g., “block,” “record,” “card image,”

etc.). Second, everything on the system that produces or accepts data is treated as a file; this includes hardware devices like disk drives and terminals. Older systems treated every device differently. Both of these ideas have made systems programmers’ lives much more pleasant.

Standard I/O 

Background Jobs

But if you want to run a command that does not require user input and you want to do other things while the command is running, put an ampersand (&) after the command

If you type diff warandpeace.txt warandpeace.txt.old &, then the system will spew lots and lots of output at you, which will be difficult to stop—even with the tech-niques explained in Chapter 7. However, if you type:

 

$ diff warandpeace.txt warandpeace.txt.old > txtdiff &

Background Jobs and Priorities  

Speaking of good citizenship, there is also a UNIX command that lets you lower the priority of any job: the aptly named nice. If you type nice command, where command can be a complex shell command line with pipes, redirectors, etc., then the command will run at a lower priority. * You can control just how much lower by giving nice a numerical argument; consult the nice manpage for details.

 

posted @ 2021-01-06 12:52  碧水东流至此回  阅读(55)  评论(0编辑  收藏  举报