fileset 함수

fileset 함수

fileset 은 경로와 패턴을 받아서 일반 파일(regular files) 이름의 집합을 열거해요.

출처: 문서

본문

fileset 은 경로와 패턴을 받아서 일반 파일 이름의 집합을 열거해요. 경로는 결과 파일 이름 집합에서 자동으로 제거되며, 경로 구분자를 아직 포함하는 결과는 크로스 시스템 호환성을 위해 항상 경로 구분자로 정방향 슬래시(/)를 반환해요.

fileset(path, pattern)

지원되는 패턴 매칭:

  • * — 비구분자(non-separator) 문자의 모든 시퀀스와 매칭
  • ** — 구분자 문자를 포함한 모든 문자의 시퀀스와 매칭
  • ? — 단일 비구분자 문자와 매칭
  • {alternative1,...} — 쉼표로 구분된 대안 중 하나가 매칭되면 문자의 시퀀스와 매칭
  • [CLASS] — 문자 클래스(class) 안의 단일 비구분자 문자와 매칭 (아래 참고)
  • [^CLASS] — 문자 클래스 밖의 단일 비구분자 문자와 매칭 (아래 참고)

문자 클래스는 다음을 지원해요:

  • [abc] — 집합 안의 단일 문자와 매칭
  • [a-z] — 범위 안의 단일 문자와 매칭

함수는 작업(job) 실행 시점이 아니라 구성 파싱 중에 CLI가 평가해요. 따라서 이 함수는 운영자(operator) 호스트의 디스크에 이미 존재하는 파일에만 사용할 수 있어요.

Examples

> tree pkr-consul
pkr-consul
├── build-linux.pkr.hcl
└── linux
    ├── files
    │   ├── hello.txt
    │   └── world.txt
    └── scripts
        ├── script-1-install.sh
        └── script-2-setup.sh

3 directories, 5 files

> fileset(".", "*")
[
  "build-linux.pkr.hcl",
]

> echo 'fileset(".", "linux/scripts/*")'
[
  "linux/scripts/script-1-install.sh",
  "linux/scripts/script-2-setup.sh",
]

> echo 'fileset("linux", "files/{hello,world}.txt")'
[
  "files/hello.txt",
  "files/world.txt",
]

> echo 'fileset("./linux/files", "*")'
[
  "hello.txt",
  "world.txt",
]

> echo 'fileset("./linux", "**")'
[
  "files/hello.txt",
  "files/world.txt",
  "scripts/script-1-install.sh",
  "scripts/script-2-setup.sh",
]

더 알아보기 (Learn more)