What Command Can Be Used to Replace Characters in a File Sent via Standard Input?
Comments. Lines beginning with a # (with the exception of #!) are comments and will not be executed.
# This line is a annotate.
Comments may as well occur following the finish of a command.
repeat "A comment will follow." # Comment hither. # ^ Note whitespace before #
Comments may likewise follow whitespace at the beginning of a line.
# A tab precedes this comment.
Comments may even exist embedded within a pipe.
initial=( `cat "$startfile" | sed -e '/#/d' | tr -d '\n' |\ # Delete lines containing '#' comment character. sed -east 's/\./\. /g' -eastward 's/_/_ /g'` ) # Excerpted from life.sh script
A control may not follow a annotate on the aforementioned line. In that location is no method of terminating the comment, in order for "live lawmaking" to begin on the same line. Use a new line for the side by side command. |
Of form, a quoted or an escaped # in an echo statement does not begin a comment. Too, a # appears in certain parameter-exchange constructs and in numerical constant expressions. |
Sure blueprint matching operations also apply the #.
Command separator [semicolon]. Permits putting two or more commands on the same line.
repeat hello; echo there if [ -x "$filename" ]; then # Note the space afterward the semicolon. #+ ^^ echo "File $filename exists."; cp $filename $filename.bak else # ^^ echo "File $filename not found."; impact $filename fi; repeat "File test complete."
Note that the ";" sometimes needs to be escaped.
Terminator in a case option [double semicolon].
example "$variable" in abc) echo "\$variable = abc" ;; xyz) repeat "\$variable = xyz" ;; esac
"dot", equally a component of a filename. When working with filenames, a leading dot is the prefix of a "hidden" file, a file that an ls will not normally show.
bash$ affect .hidden-file bash$ ls -l full 10 -rw-r--r-- 1 bozo 4034 Jul 18 22:04 data1.addressbook -rw-r--r-- i bozo 4602 May 25 thirteen:58 data1.addressbook.bak -rw-r--r-- i bozo 877 Dec 17 2000 employment.addressbook bash$ ls -al total 14 drwxrwxr-x ii bozo bozo 1024 Aug 29 xx:54 ./ drwx------ 52 bozo bozo 3072 Aug 29 20:51 ../ -rw-r--r-- 1 bozo bozo 4034 Jul 18 22:04 data1.addressbook -rw-r--r-- one bozo bozo 4602 May 25 13:58 data1.addressbook.bak -rw-r--r-- 1 bozo bozo 877 Dec 17 2000 employment.addressbook -rw-rw-r-- 1 bozo bozo 0 Aug 29 20:54 .subconscious-file
When considering directory names, a single dot represents the electric current working directory, and two dots denote the parent directory.
bash$ pwd /dwelling house/bozo/projects fustigate$ cd . bash$ pwd /home/bozo/projects bash$ cd .. bash$ pwd /home/bozo/
The dot ofttimes appears as the destination (directory) of a file move command, in this context meaning current directory.
bash$ cp /dwelling/bozo/current_work/junk/* .
fractional quoting [double quote]. "Cord" preserves (from estimation) well-nigh of the special characters within Cord. Come across Chapter 5.
total quoting [single quote]. 'STRING' preserves all special characters within STRING. This is a stronger course of quoting than "String". See Chapter 5.
comma operator. The comma operator [i] links together a series of arithmetic operations. All are evaluated, just only the last one is returned.
permit "t2 = ((a = 9, fifteen / iii))" # Set up "a = 9" and "t2 = 15 / 3"
The comma operator can also concatenate strings.
for file in /{,usr/}bin/*calc # ^ Observe all executable files ending in "calc" #+ in /bin and /usr/bin directories. do if [ -x "$file" ] and then echo $file fi washed # /bin/ipcalc # /usr/bin/kcalc # /usr/bin/oidcalc # /usr/bin/oocalc # Thank you, Rory Winston, for pointing this out.
escape [backslash]. A quoting mechanism for single characters.
\X escapes the character Ten. This has the result of "quoting" X, equivalent to 'X'. The \ may be used to quote " and ', so they are expressed literally.
See Chapter 5 for an in-depth caption of escaped characters.
Filename path separator [forward slash]. Separates the components of a filename (as in /home/bozo/projects/Makefile).
This is also the division arithmetic operator.
command substitution. The `command` construct makes available the output of command for assignment to a variable. This is also known every bit backquotes or backticks.
nix command [colon]. This is the shell equivalent of a "NOP" ( no op , a do-zip operation). It may exist considered a synonym for the crush builtin true. The ":" command is itself a Fustigate builtin, and its exit condition is true (0).
Endless loop:
while : do performance-1 functioning-ii ... functioning-north done # Same every bit: # while truthful # practise # ... # done
Placeholder in if/then exam:
if condition then : # Practice nothing and branch ahead else # Or else ... take-some-activity fi
Provide a placeholder where a binary operation is expected, see Instance viii-2 and default parameters.
: ${username=`whoami`} # ${username=`whoami`} Gives an error without the leading : # unless "username" is a command or builtin... : ${1?"Usage: $0 Statement"} # From "usage-message.sh example script.
Provide a placeholder where a command is expected in a here document. See Example 19-ten.
Evaluate string of variables using parameter substitution (as in Example 10-7).
: ${HOSTNAME?} ${USER?} ${Postal service?} # Prints error message #+ if one or more of essential ecology variables not set up.
Variable expansion / substring replacement.
In combination with the > redirection operator, truncates a file to zero length, without changing its permissions. If the file did not previously exist, creates information technology.
: > data.xxx # File "data.xxx" at present empty. # Same effect as cat /dev/zippo >data.xxx # However, this does not fork a new process, since ":" is a builtin.
In combination with the >> redirection operator, has no effect on a pre-existing target file ( : >> target_file ). If the file did not previously exist, creates information technology.
This applies to regular files, non pipes, symlinks, and certain special files. |
May exist used to brainstorm a comment line, although this is not recommended. Using # for a comment turns off error checking for the remainder of that line, then almost anything may announced in a comment. However, this is not the example with :.
: This is a comment that generates an error, ( if [ $x -eq 3] ).
The ":" serves as a field separator, in /etc/passwd, and in the $PATH variable.
bash$ echo $PATH /usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/usr/games
A colon is adequate as a function name.
:() { echo "The name of this function is "$FUNCNAME" " # Why employ a colon as a function name? # It'southward a way of obfuscating your code. } : # The name of this function is :
A colon tin can serve every bit a placeholder in an otherwise empty function.
not_empty () { : } # Contains a : (null command), and so is not empty.
reverse (or negate) the sense of a test or exit status [bang]. The ! operator inverts the exit status of the command to which it is practical (see Example 6-ii). It also inverts the pregnant of a exam operator. This can, for example, change the sense of equal ( = ) to non-equal ( != ). The ! operator is a Bash keyword.
In a different context, the ! also appears in indirect variable references.
In yet another context, from the control line, the ! invokes the Bash history mechanism (see Appendix 50). Notation that within a script, the history mechanism is disabled.
wild menu [asterisk]. The * grapheme serves as a "wild card" for filename expansion in globbing. By itself, it matches every filename in a given directory.
bash$ echo * abs-book.sgml add-bulldoze.sh agram.sh allonym.sh
The * likewise represents whatsoever number (or cipher) characters in a regular expression.
arithmetic operator. In the context of arithmetics operations, the * denotes multiplication.
** A double asterisk can represent the exponentiation operator or extended file-match globbing.
test operator. Inside certain expressions, the ? indicates a test for a condition.
In a double-parentheses construct, the ? can serve every bit an element of a C-style trinary operator. [ii]
status ? result-if-true : result-if-false
(( var0 = var1<98?nine:21 )) # ^ ^ # if [ "$var1" -lt 98 ] # then # var0=ix # else # var0=21 # fi
In a parameter substitution expression, the ? tests whether a variable has been set.
Variable substitution (contents of a variable).
var1=5 var2=23skidoo echo $var1 # five echo $var2 # 23skidoo
A $ prefixing a variable name indicates the value the variable holds.
Quoted cord expansion. This construct expands single or multiple escaped octal or hex values into ASCII [3] or Unicode characters.
process ID variable. The $$ variable holds the process ID [4] of the script in which information technology appears.
command group.
A listing of commands within parentheses starts a subshell. Variables inside parentheses, within the subshell, are non visible to the rest of the script. The parent process, the script, cannot read variables created in the kid process, the subshell. |
assortment initialization.
Array=(element1 element2 element3)
Caryatid expansion.
repeat \"{These,words,are,quoted}\" # " prefix and suffix # "These" "words" "are" "quoted" cat {file1,file2,file3} > combined_file # Concatenates the files file1, file2, and file3 into combined_file. cp file22.{txt,backup} # Copies "file22.txt" to "file22.backup"
A command may act upon a comma-separated listing of file specs within braces . [five] Filename expansion (globbing) applies to the file specs between the braces.
No spaces allowed within the braces unless the spaces are quoted or escaped. echo {file1,file2}\ :{\ A," B",' C'} file1 : A file1 : B file1 : C file2 : A file2 : B file2 : C |
Extended Caryatid expansion.
echo {a..z} # a b c d e f 1000 h i j k l m northward o p q r south t u v w x y z # Echoes characters between a and z. repeat {0..3} # 0 1 2 3 # Echoes characters between 0 and 3. base64_charset=( {A..Z} {a..z} {0..ix} + / = ) # Initializing an array, using extended caryatid expansion. # From vladz's "base64.sh" instance script.
The {a..z} extended brace expansion construction is a feature introduced in version 3 of Bash.
Block of code [curly brackets]. Too referred to as an inline grouping, this construct, in effect, creates an anonymous function (a office without a name). However, dissimilar in a "standard" function, the variables inside a code block remain visible to the residue of the script.
fustigate$ { local a; a=123; } bash: local: tin can but exist used in a function
a=123 { a=321; } echo "a = $a" # a = 321 (value inside lawmaking block) # Thanks, Due south.C.
The code block enclosed in braces may have I/O redirected to and from it.
Example 3-1. Code blocks and I/O redirection
#!/bin/fustigate # Reading lines in /etc/fstab. File=/etc/fstab { read line1 read line2 } < $File echo "Outset line in $File is:" echo "$line1" repeat echo "Second line in $File is:" repeat "$line2" exit 0 # Now, how do yous parse the separate fields of each line? # Hint: use awk, or . . . # . . . Hans-Joerg Diers suggests using the "set" Bash builtin.
Example 3-2. Saving the output of a lawmaking block to a file
#!/bin/fustigate # rpm-check.sh # Queries an rpm file for description, list, #+ and whether it can be installed. # Saves output to a file. # # This script illustrates using a code block. SUCCESS=0 E_NOARGS=65 if [ -z "$1" ] and so echo "Usage: `basename $0` rpm-file" exit $E_NOARGS fi { # Begin code block. repeat echo "Archive Description:" rpm -qpi $1 # Query description. echo echo "Annal Listing:" rpm -qpl $ane # Query listing. echo rpm -i --test $1 # Query whether rpm file can be installed. if [ "$?" -eq $SUCCESS ] then echo "$1 tin be installed." else repeat "$one cannot be installed." fi echo # Finish code block. } > "$i.exam" # Redirects output of everything in block to file. echo "Results of rpm test in file $1.test" # Run into rpm human folio for explanation of options. get out 0
Unlike a command grouping within (parentheses), as above, a code cake enclosed past {braces} volition non commonly launch a subshell. [half-dozen] It is possible to iterate a code block using a non-standard for-loop. |
placeholder for text. Used later xargs -i (supersede strings option). The {} double curly brackets are a placeholder for output text.
ls . | xargs -i -t cp ./{} $1 # ^^ ^^ # From "ex42.sh" (copydir.sh) example.
pathname. Mostly used in find constructs. This is not a shell builtin.
The ";" ends the -exec pick of a observe command sequence. It needs to be escaped to protect it from interpretation by the shell. |
examination.
Test expression between [ ]. Note that [ is part of the trounce builtin exam (and a synonym for it), non a link to the external control /usr/bin/test.
exam.
Examination expression between [[ ]]. More than flexible than the single-bracket [ ] examination, this is a shell keyword.
See the give-and-take on the [[ ... ]] construct.
array element.
In the context of an array, brackets set off the numbering of each element of that array.
Array[1]=slot_1 echo ${Array[one]}
range of characters.
As office of a regular expression, brackets delineate a range of characters to match.
integer expansion.
Evaluate integer expression between $[ ].
a=3 b=7 repeat $[$a+$b] # ten repeat $[$a*$b] # 21
Note that this usage is deprecated, and has been replaced by the (( ... )) construct.
integer expansion.
Expand and evaluate integer expression between (( )).
Come across the discussion on the (( ... )) construct.
scriptname >filename redirects the output of scriptname to file filename. Overwrite filename if information technology already exists.
command &>filename redirects both the stdout and the stderr of command to filename.
This is useful for suppressing output when testing for a condition. For case, permit united states of america test whether a certain control exists.
Or in a script:
|
command >&two redirects stdout of command to stderr.
scriptname >>filename appends the output of scriptname to file filename. If filename does not already exist, information technology is created.
[i]<>filename opens file filename for reading and writing, and assigns file descriptor i to information technology. If filename does not exist, it is created.
(command)>
<(control)
In a dissimilar context, the "<" and ">" characters human action every bit string comparison operators.
In yet another context, the "<" and ">" characters act as integer comparison operators. See also Example 16-nine.
ASCII comparison.
veg1=carrots veg2=tomatoes if [[ "$veg1" < "$veg2" ]] then repeat "Although $veg1 precede $veg2 in the lexicon," echo -due north "this does not necessarily imply anything " repeat "nearly my culinary preferences." else echo "What kind of dictionary are you using, anyhow?" fi
fustigate$ grep '\<the\>' textfile
pipe. Passes the output (stdout) of a previous command to the input (stdin) of the next one, or to the shell. This is a method of chaining commands together.
repeat ls -l | sh # Passes the output of "echo ls -50" to the beat, #+ with the same outcome as a uncomplicated "ls -l". true cat *.lst | sort | uniq # Merges and sorts all ".lst" files, then deletes indistinguishable lines.
The output of a control or commands may exist piped to a script.
#!/bin/fustigate # uppercase.sh : Changes input to uppercase. tr 'a-z' 'A-Z' # Letter of the alphabet ranges must be quoted #+ to prevent filename generation from single-letter filenames. get out 0
bash$ ls -l | ./capital letter.sh -RW-RW-R-- 1 BOZO BOZO 109 April 7 nineteen:49 1.TXT -RW-RW-R-- 1 BOZO BOZO 109 APR 14 xvi:48 two.TXT -RW-R--R-- 1 BOZO BOZO 725 April 20 20:56 Information-FILE
The stdout of each process in a pipe must exist read equally the stdin of the adjacent. If this is non the example, the information stream will block, and the pipe will non bear as expected. A pipe runs equally a child process, and therefore cannot alter script variables. If one of the commands in the pipe aborts, this prematurely terminates execution of the pipe. Chosen a broken pipage, this condition sends a SIGPIPE point. |
force redirection (even if the noclobber option is set). This will forcibly overwrite an existing file.
OR logical operator. In a test construct, the || operator causes a return of 0 (success) if either of the linked test conditions is truthful.
Run job in groundwork. A command followed by an & will run in the groundwork.
bash$ sleep x & [1] 850 [1]+ Done sleep 10
Inside a script, commands and even loops may run in the background.
Instance three-three. Running a loop in the groundwork
#!/bin/bash # background-loop.sh for i in i 2 3 4 5 six 7 8 9 10 # First loop. do echo -due north "$i " washed & # Run this loop in groundwork. # Will sometimes execute subsequently 2d loop. echo # This 'repeat' sometimes will not display. for i in 11 12 13 14 fifteen 16 17 eighteen xix twenty # Second loop. do echo -n "$i " washed repeat # This 'echo' sometimes will not display. # ====================================================== # The expected output from the script: # ane 2 3 4 5 half-dozen seven 8 9 10 # 11 12 13 fourteen 15 16 17 18 xix 20 # Sometimes, though, you get: # 11 12 xiii 14 fifteen 16 17 18 xix 20 # 1 two 3 4 v six 7 8 nine 10 bozo $ # (The second 'echo' doesn't execute. Why?) # Occasionally besides: # one ii 3 iv 5 6 seven viii 9 ten xi 12 13 xiv 15 sixteen 17 18 nineteen 20 # (The first 'repeat' doesn't execute. Why?) # Very rarely something like: # eleven 12 13 1 two 3 four five half dozen seven viii 9 10 14 15 16 17 eighteen 19 20 # The foreground loop preempts the groundwork i. get out 0 # Nasimuddin Ansari suggests adding slumber i #+ after the repeat -north "$i" in lines 6 and 14, #+ for some real fun.
A command run in the background inside a script may cause the script to hang, waiting for a keystroke. Fortunately, at that place is a remedy for this. |
AND logical operator. In a test construct, the && operator causes a return of 0 (success) merely if both the linked test atmospheric condition are truthful.
COMMAND -[Option1][Option2][...]
ls -al
sort -dfu $filename
if [ $file1 -ot $file2 ] then # ^ echo "File $file1 is older than $file2." fi if [ "$a" -eq "$b" ] and so # ^ echo "$a is equal to $b." fi if [ "$c" -eq 24 -a "$d" -eq 47 ] then # ^ ^ echo "$c equals 24 and $d equals 47." fi param2=${param1:-$DEFAULTVAL} # ^
--
The double-dash -- prefixes long (verbatim) options to commands.
sort --ignore-leading-blanks
Used with a Fustigate builtin, information technology means the cease of options to that particular command.
This provides a handy ways of removing files whose names brainstorm with a nuance. |
The double-nuance is too used in conjunction with set up.
set -- $variable (as in Example xv-18)
redirection from/to stdin or stdout [nuance].
bash$ true cat - abc abc ... Ctl-D
As expected, true cat - echoes stdin, in this example keyboarded user input, to stdout. But, does I/O redirection using - accept existent-earth applications?
(cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -) # Move entire file tree from 1 directory to some other # [courtesy Alan Cox <a.cox@swansea.ac.uk>, with a minor alter] # 1) cd /source/directory # Source directory, where the files to be moved are. # 2) && # "And-listing": if the 'cd' functioning successful, # then execute the next command. # 3) tar cf - . # The 'c' pick 'tar' archiving command creates a new annal, # the 'f' (file) choice, followed by '-' designates the target file # every bit stdout, and practice it in current directory tree ('.'). # 4) | # Piped to ... # 5) ( ... ) # a subshell # half-dozen) cd /dest/directory # Alter to the destination directory. # 7) && # "And-list", as above # viii) tar xpvf - # Unarchive ('x'), preserve buying and file permissions ('p'), # and send verbose messages to stdout ('v'), # reading data from stdin ('f' followed past '-'). # # Note that 'x' is a command, and 'p', 'v', 'f' are options. # # Whew! # More elegant than, but equivalent to: # cd source/directory # tar cf - . | (cd ../dest/directory; tar xpvf -) # # Also having aforementioned effect: # cp -a /source/directory/* /dest/directory # Or: # cp -a /source/directory/* /source/directory/.[^.]* /dest/directory # If there are hidden files in /source/directory.
bunzip2 -c linux-2.6.16.tar.bz2 | tar xvf - # --uncompress tar file-- | --and then pass it to "tar"-- # If "tar" has not been patched to handle "bunzip2", #+ this needs to be done in two discrete steps, using a pipe. # The purpose of the exercise is to unarchive "bzipped" kernel source.
Note that in this context the "-" is not itself a Bash operator, but rather an option recognized by certain UNIX utilities that write to stdout, such every bit tar, cat, etc.
bash$ echo "whatever" | true cat - any
Where a filename is expected, - redirects output to stdout (sometimes seen with tar cf ), or accepts input from stdin, rather than from a file. This is a method of using a file-oriented utility equally a filter in a pipe.
bash$ file Usage: file [-bciknvzL] [-f namefile] [-1000 magicfiles] file...
Add a "-" for a more useful upshot. This causes the shell to await user input.
fustigate$ file - abc standard input: ASCII text fustigate$ file - #!/bin/fustigate standard input: Bourne-Once more crush script text executable
The "-" can exist used to piping stdout to other commands. This permits such stunts every bit prepending lines to a file.
Using diff to compare a file with a section of another:
grep Linux file1 | diff file2 -
Finally, a existent-world example using - with tar.
Example three-4. Backup of all files changed in last day
#!/bin/bash # Backs up all files in current directory modified within last 24 hours #+ in a "tarball" (tarred and gzipped file). BACKUPFILE=backup-$(date +%1000-%d-%Y) # Embeds appointment in fill-in filename. # Thanks, Joshua Tschida, for the idea. archive=${one:-$BACKUPFILE} # If no backup-annal filename specified on command-line, #+ it volition default to "backup-MM-DD-YYYY.tar.gz." tar cvf - `notice . -mtime -1 -type f -print` > $archive.tar gzip $archive.tar echo "Directory $PWD backed up in archive file \"$archive.tar.gz\"." # Stephane Chazelas points out that the above lawmaking will fail #+ if there are too many files constitute #+ or if whatever filenames comprise bare characters. # He suggests the following alternatives: # ------------------------------------------------------------------- # detect . -mtime -1 -type f -print0 | xargs -0 tar rvf "$annal.tar" # using the GNU version of "discover". # find . -mtime -1 -type f -exec tar rvf "$archive.tar" '{}' \; # portable to other UNIX flavors, just much slower. # ------------------------------------------------------------------- exit 0
Filenames starting time with "-" may cause problems when coupled with the "-" redirection operator. A script should check for this and add together an appropriate prefix to such filenames, for case ./-FILENAME, $PWD/-FILENAME, or $PATHNAME/-FILENAME. If the value of a variable begins with a - , this may likewise create problems. |
previous working directory. A cd - command changes to the previous working directory. This uses the $OLDPWD environmental variable.
Exercise not confuse the "-" used in this sense with the "-" redirection operator but discussed. The estimation of the "-" depends on the context in which information technology appears. |
In a different context, the "=" is a string comparison operator.
In a different context, the + is a Regular Expression operator.
Pick. Selection flag for a control or filter.
Certain commands and builtins use the + to enable certain options and the - to disable them. In parameter substitution, the + prefixes an alternate value that a variable expands to.
permit "z = 5 % 3" echo $z # 2
In a different context, the % is a pattern matching operator.
abode directory [tilde]. This corresponds to the $Domicile internal variable. ~bozo is bozo's home directory, and ls ~bozo lists the contents of it. ~/ is the current user's abode directory, and ls ~/ lists the contents of it.
bash$ echo ~bozo /domicile/bozo bash$ echo ~ /home/bozo fustigate$ echo ~/ /habitation/bozo/ bash$ repeat ~: /home/bozo: bash$ echo ~nonexistent-user ~nonexistent-user
current working directory. This corresponds to the $PWD internal variable.
previous working directory. This corresponds to the $OLDPWD internal variable.
modify the beliefs of the terminal or text brandish. A control character is a CONTROL + key combination (pressed simultaneously). A control grapheme may also be written in octal or hexadecimal notation, post-obit an escape.
Command characters are not normally useful within a script.
-
Ctl-A
Moves cursor to beginning of line of text (on the command-line).
-
Ctl-B
Backspace (nondestructive).
-
Ctl-C
Break . Terminate a foreground task.
-
Ctl-D
Log out from a shell (similar to exit).
EOF (cease-of-file). This likewise terminates input from stdin.
When typing text on the console or in an xterm window, Ctl-D erases the grapheme under the cursor. When there are no characters present, Ctl-D logs out of the session, every bit expected. In an xterm window, this has the effect of closing the window.
-
Ctl-East
Moves cursor to end of line of text (on the command-line).
-
Ctl-F
Moves cursor frontward i grapheme position (on the control-line).
-
Ctl-G
BEL . On some old-time teletype terminals, this would actually ring a bell. In an xterm it might beep.
-
Ctl-H
Rubout (destructive backspace). Erases characters the cursor backs over while backspacing.
#!/bin/bash # Embedding Ctl-H in a string. a="^H^H" # Two Ctl-H's -- backspaces # ctl-V ctl-H, using vi/vim echo "abcdef" # abcdef echo echo -due north "abcdef$a " # abcd f # Infinite at end ^ ^ Backspaces twice. repeat echo -northward "abcdef$a" # abcdef # No space at end ^ Doesn't backspace (why?). # Results may non be quite equally expected. echo; echo # Constantin Hagemeier suggests trying: # a=$'\010\010' # a=$'\b\b' # a=$'\x08\x08' # But, this does not change the results. ######################################## # At present, try this. rubout="^H^H^H^H^H" # 5 ten Ctl-H. echo -n "12345678" sleep two repeat -n "$rubout" sleep 2
-
Ctl-I
Horizontal tab .
-
Ctl-J
Newline (line feed). In a script, may likewise be expressed in octal note -- '\012' or in hexadecimal -- '\x0a'.
-
Ctl-K
Vertical tab .
When typing text on the console or in an xterm window, Ctl-K erases from the character nether the cursor to cease of line. Within a script, Ctl-Grand may conduct differently, equally in Lee Lee Maschmeyer's example, below.
-
Ctl-L
Formfeed (clear the terminal screen). In a terminal, this has the same effect as the clear command. When sent to a printer, a Ctl-L causes an accelerate to end of the paper sheet.
-
Ctl-M
Carriage return .
#!/bin/bash # Thank you, Lee Maschmeyer, for this example. read -n 1 -s -p \ $'Control-K leaves cursor at beginning of this line. Press Enter. \x0d' # Of form, '0d' is the hex equivalent of Control-Thousand. echo >&2 # The '-southward' makes anything typed silent, #+ so it is necessary to become to new line explicitly. read -n 1 -s -p $'Control-J leaves cursor on next line. \x0a' # '0a' is the hex equivalent of Control-J, linefeed. echo >&2 ### read -n one -s -p $'And Control-M\x0bgoes direct down.' echo >&two # Control-K is vertical tab. # A better example of the consequence of a vertical tab is: var=$'\x0aThis is the bottom line\x0bThis is the top line\x0a' echo "$var" # This works the same way as the above instance. However: echo "$var" | col # This causes the correct cease of the line to exist college than the left finish. # It besides explains why we started and ended with a line feed -- #+ to avert a garbled screen. # Every bit Lee Maschmeyer explains: # -------------------------- # In the [offset vertical tab example] . . . the vertical tab #+ makes the printing go straight downward without a railroad vehicle render. # This is true only on devices, such every bit the Linux console, #+ that tin't go "astern." # The real purpose of VT is to go direct UP, non downwardly. # It can be used to print superscripts on a printer. # The col utility can be used to emulate the proper beliefs of VT. exit 0
-
Ctl-Northward
Erases a line of text recalled from history buffer [8] (on the command-line).
-
Ctl-O
Issues a newline (on the command-line).
-
Ctl-P
Recalls last command from history buffer (on the command-line).
-
Ctl-Q
Resume ( XON ).
This resumes stdin in a terminal.
-
Ctl-R
Backwards search for text in history buffer (on the command-line).
-
Ctl-S
Suspend ( XOFF ).
This freezes stdin in a terminal. (Utilize Ctl-Q to restore input.)
-
Ctl-T
Reverses the position of the character the cursor is on with the previous character (on the command-line).
-
Ctl-U
Erase a line of input, from the cursor backward to beginning of line. In some settings, Ctl-U erases the entire line of input, regardless of cursor position.
-
Ctl-V
When inputting text, Ctl-5 permits inserting command characters. For example, the following two are equivalent:
echo -e '\x0a' repeat <Ctl-V><Ctl-J>
Ctl-V is primarily useful from within a text editor.
-
Ctl-W
When typing text on the console or in an xterm window, Ctl-W erases from the graphic symbol under the cursor backwards to the showtime case of whitespace. In some settings, Ctl-W erases backwards to starting time non-alphanumeric character.
-
Ctl-X
In sure word processing programs, Cuts highlighted text and copies to clipboard.
-
Ctl-Y
Pastes back text previously erased (with Ctl-U or Ctl-Westward ).
-
Ctl-Z
Pauses a foreground job.
Substitute operation in certain word processing applications.
EOF (finish-of-file) character in the MSDOS filesystem.
functions every bit a separator between commands and/or variables. Whitespace consists of either spaces, tabs, blank lines, or whatever combination thereof. [ix] In some contexts, such every bit variable assignment, whitespace is not permitted, and results in a syntax error.
Bare lines have no effect on the action of a script, and are therefore useful for visually separating functional sections.
$IFS, the special variable separating fields of input to certain commands. Information technology defaults to whitespace.
To preserve whitespace inside a string or in a variable, employ quoting.
UNIX filters can target and operate on whitespace using the POSIX character class [:space:].
Source: https://tldp.org/LDP/abs/html/special-chars.html
0 Response to "What Command Can Be Used to Replace Characters in a File Sent via Standard Input?"
Post a Comment