Be playful in bash

Source: Internet
Author: User
Document directory
  • Event designators
  • Word designators
  • Modifiers
History expansionevent designators

An event designator is a reference to a command line entry in thehistory list.

!
Start a history substitution, when T when followed by Blank, Newline, carriage return, = or (when ExtglobShell option is enabled usingthe ShoptBuiltin ).
! N
Refer to command line N.
! - N
Refer to the current command line minus N.
!!
Refer to the previous command. This is a synonym '! -1 '.
! String
Refer to the most recent command starting String.
!? String [?]
Refer to the most recent command containing String. The Trailing ?May be omitted if StringIs followed immediately by a newline.
^ String1^ String2^
Quick substitution. Repeat the last command, replacing String1With String2. Equivalent ''!! : S/ String1/ String2/''(See ModifiersBelow ).
! #
The entire command line typed so far.
Word designators

Word designators are used to select desired words from the event.:Separates the event specification from the word designator. It may be omitted if the word designator begins with^,$,*,-, Or%. Words are numbered from the beginning of the line, with the first word being denoted by 0 (zero). Words are inserted into the current line separated by single spaces.

0 (zero)
The zeroth word. For the shell, This Is The commandword.
N
The NTh word.
^
The first argument. That is, word 1.
$
The last argument.
%
The word matched by the most recent '? String? 'Search.
X -Y
A range of words ;'- Y'Abbreviate' 0- Y'.
*
All of the words but the zeroth. This is a synonymfor' 1-$'. It is not an error to use *If there is just oneword In the event; the empty string is returned in that case.
X *
Abbreviates X-$.
X-
Abbreviates X-$Like X *, But omits the last word.

If a word designator is supplied without an event specification, theprevious command is used as the event.

 

Modifiers

After the optional word designator, there may appear a sequence ofone or more of the following modifiers, each preceded by ':'.

 

H
Remove a trailing file name component, leaving only the head.
T
Remove all leading file name components, leaving the tail.
R
Remove a trailing Suffix of the form . Xxx, Leaving thebasename.
E
Remove all but the trailing suffix.
P
Print the new command but do not execute it.
Q
Quote the substituted words, escaping further substitutions.
X
Quote the substituted words as Q, But break into words BlanksAnd newlines.
S/ Old/ New/
Substitute NewFor the first occurrence OldIn the event line. Any delimiter can be used in place of/. thefinal Delimiter is optional if it is the last character of theevent line. The delimiter may be quoted in OldAnd NewWith a single backslash. If & appears in New, It is replaced Old. A single backslash will quote the &. If OldIs null, it is set to the last OldSubstituted, or, if no previous history substitutions took place, the last StringIn !? String [?]Search.
&
Repeat the previous substitution.
G
Cause changes to be applied over the entire event line. This isused in conjunction' : S'(E.g .,' : GS/ Old/ New/') Or' :&'. If used' : S', Any delimiter can be usedin place of/, and the final Delimiter is optionalif it is the last character of the event line. AMay be used as a synonym G.
G
Apply the following' S'Modifier once to each word in the event line.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.