Linux 시스템 의 특수 변수
4955 단어 시시 하 다
$매개 변수 관련 명령
$$ 현재 셸 의 PID $! 셸 이 마지막 으로 실행 중인 배경 프로 세 스 PID 용도: 배경 에서 실행 중인 프로그램 을 닫 습 니 다.[root@master ~]# sleep 100 &
[1] 8127
[root@master ~]# kill -9 $!
$? 이전 명령 이 실 행 된 반환 값 (종료 코드, int 형식) $- 셸 의 사용 가능 한 옵션, 예 를 들 어 echo $- 은 출력 himBH, echo 명령 은 -h -i -m -B -H $# $0 입력 한 매개 변수 개수 $n ~ $0 입력 한 매개 변수 값, $1현재 셸 스 크 립 트 파일 이름 입 니 다. args 뒤 에는 각 매개 변수 가 있 습 니 다. 프로그램 $* 매개 변수 가 받 은 내용 과 일치 합 니 다. "" 모든 입력 매개 변수 목록 은 $@ 괄호 로 빈 칸 을 간격 문자 로 사용 하 는 목록 "" 을 표시 합 니 다. 모든 입력 매개 변수 목록 을 표시 합 니 다. 유일한 차이 점 은 작은 따옴표 로 묶 는 것 입 니 다. 사용 history패 키 지 를 감 싸 고 간격 문자 로 빈 칸 을 사용 하 는 매개 변수 목록히 스토리 관련 명령
↑ 역사 명령 을 직접 열거 합 니 다 !1 명령 을 계속 누 르 지 않 아 도 됩 니 다)!-1 은 제1조 명령 을 집행 한 다 는 뜻 이 고, 1 도 다른 숫자 !! 로 바 꾸 어 마지막 명령 을 집행 한 다 는 뜻 이 며, 1 도 다른 숫자 !-1 로 바 꿀 수 있다.이 문자열 을 포함 하 는 최근 명령 을 가리 키 며 실행 ! 최근 문자열 을 포함 하 는 명령 을 출력 합 니 다.History 에서 이전 명령 의 인 자 를 가 져 왔 습 니 다.
!? 마지막 매개 변수 용도 획득: 폴 더 를 만 들 고 들 어가 기[root@master ~]# mkdir -p test/test2
[root@master ~]# cd !$
cd test/test2
[root@master test2]#
echo !? 첫 번 째 매개 변수 !$ 획득 모든 매개 변수 !^ 획득 두 번 째 매개 변수 !* 획득 두 번 째 매개 변수 !:2 획득 두 번 째 부터 마지막 매개 변수 !:2-3 획득 두 번 째 부터 마지막 매개 변수 !:2-$ 획득 세 번 째 부터 마지막 두 번 째 매개 변수 !:2* 획득 0 번 째 매개 변수 (명령 자체) 획득단축 키 를 사용 하여 이전 명령 의 다른 인 자 를 얻 습 니 다.
!:3- + !:0, 그리고 Alt + 0 + Alt 가 0 번 째 인 자 를 얻 었 습 니 다. 0 은 다른 숫자 Ctrl + y 로 바 꿀 수 있 습 니 다. 그리고 Alt + - + Alt 가 마지막 인 자 를 얻 었 습 니 다 Ctrl + y 가 마지막 인 자 를 얻 었 습 니 다.조회 방법
$ man -P 'less -p ^HISTORY\ EXPANSION' bash
<...>
Word Designators
Word designators are used to select desired words from the event.
A : separates the event specification from the word designator.
It may be omitted if the word designator begins with a ^, $, *, -,
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 command word.
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’ abbreviates ‘0-y’.
* All of the words but the zeroth.
This is a synonym for ‘1-$’.
It is not an error to use * if there is just one word 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, the previous command is used as the event.