Expr
| 원저자 | Dick Haight |
|---|---|
| 개발자 | AT&T 벨 연구소 |
| 발표일 | 1979년 |
| 운영 체제 | 유닉스, 유닉스 계열 |
| 종류 | 명령어 |
expr은 명령 줄 유닉스 유틸리티의 하나로, 식을 평가하고 일치하는 값을 출력한다. 유닉스 v7에 처음 등장하였다.
문법: expr (식)
expr은 패턴 일치 정규 표현식을 포함하여 정수나 문자열 식을 평가한다.
사용 가능한 연산자는 다음과 같다.
- 정수의 경우: 더하기, 빼기, 곱하기, 나누기, 계수(modulus)
- 문자열의 경우: 정규 표현식 찾기, 문자열 내의 문자들의 집합을 찾기. 일부 버전에서는: 부스트링 찾기, 문자열의 길이
- 둘 중 하나에 대해: 비교 (동등, 동등하지 않음, 보다 작음 등)
다음은 불리언 식을 수반하는 예이다:
expr length "abcdef" "<" 5 "|" 15 - 4 ">" 8
이 예의 출력값은 "1"이다. 길이 "abcdef"가 6인데, 이는 5 보다 작지 않기 때문에 발생한다. (그러므로 |의 좌측은 0을 반환) 그러나 15 빼기 4는 11이며 이는 8보다 크므로 우측은 참이 되며 "or"를 참으로 만들면서 결과값이 1로 된다. 프로그램 종료 상태는 이 예에서 0으로 된다.
순수 산술에서 bc를 사용하는 것이 더 편리한 경우도 있다. 이를테면 다음과 같다:
echo "3*4+14/2" | bc
식을 하나의 문으로 받아들인다.
같이 보기
외부 링크
- expr invocation in GNU coreutils manual 보관됨 2021-04-27 - 웨이백 머신
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.