기본 콘텐츠로 건너뛰기

Bash 에서 줄 단위로 배열에 대입

Bash에서 여러 줄 데이터를 배열로 대입할 때마다 구글에 물어봤는데, 다시 찾기 귀찮아서 정리...

Bash 4.x 이상

# mapfile과 readarray는 정확히 동일한 명령이며, readarray는 mapfile은 별칭(alias)이다.

mapfile -t lines <<< ${multiline}

# 중간에 띄어 쓰기가 있을 경우, 아래와 같은 형태를 사용한다.
mapfile -t files < <(find . -type f)
for file in "${files[@]}"; do
  echo "${file}"
done

Bash 3.x 이하

IFS=$'\n' read -d '' -r -a lines <<< ${multilines}

댓글

이 블로그의 인기 게시물

탐색기에서 OneDrive 이 2개로 보이는 문제

왜 2개가 보이는지 모르겠지만, Registry 삭제하면 됨 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace 하위 키에서 OneDrive 둘 중에 하나만 지워도 바로 반영됨. 참조:  https://answers.microsoft.com/en-us/msoffice/forum/all/duplicate-onedrives-in-file-explorer/49c935a6-287b-43a5-aed5-2dee2a1c1b22