
터미널에서 명령을 내리는 동안 줄 끝에 매개변수를 전달하고 싶습니다.
그래서 저는 아래 예와 같은 것을 원합니다
find /path/to/directory -type f -exec grep -irl "SEARCH_PATTERN" {} \;
다음과 같은 형식입니다.
find /path/to/directory -type f -exec grep -irl "$1" {} \; < "SEARCH_PATTERN"
이렇게 하면 매번 가서 해당 부분의 명령을 변경할 필요가 없습니다 -irl "SEARCH_PATTERN"
. 대신 줄 끝에서 더 쉽게 설명하겠습니다.
미리 감사드립니다
답변1
함수를 생성합니다:
mygrep() { find /path -type f -exec grep -irl "$1" {} +; }
mygrep waldo
사실, 왜 필요한가요 find
?
mygrep() { grep -irl "$1" /path; }
답변2
지금 당장 생각할 수 있는 것은 이 특별한 경우에 대해 SEARCH_PATTERN 환경 변수를 생성하고 이를 사용하고 싶을 때마다 사용하는 것입니다.
빠른 예;
$ SEARCH_PAT="abc"
$ find /path -type f -exec grep -irl "${SEARCH_PAT}" {} \;
$ SEARCH_PAT="xyz"
$ find /path -type f -exec grep -irl "${SEARCH_PAT}" {} \;
등...