programing

Powershell Console에서 여러 줄 문자열을 할당하는 방법

lovejava 2023. 11. 5. 10:47

Powershell Console에서 여러 줄 문자열을 할당하는 방법

이를 Powershell Console에 입력하면

$test=@'
Test
Test'@

그리고 여러번 입력하면 계속 인쇄됩니다.

>>

그래서 나는 절대 지휘를 끝낼 수 없습니다.

무엇을 해야 하나?

'@줄에서 제일 먼저 해야 하거나 문자열의 일부로 간주해야 합니다.

$test=@'
Test
Test
'@

이 접근 방식은 또한 다음과 같이 작동합니다.@"/"@

$test=@'
Test
Test
'@

유의해야 할 점은 구분 기호에 (보이지 않는) 캐리지 리턴이 포함되어 있다는 것입니다.시작 태그 끝에 하나가 있어야 하고, 종료 태그 앞에 하나가 있어야 합니다.

PowerShell Best Practices and Style Guide최대 길이에 대한 섹션에 따르면 다음과 같이 문자열을 "분할"하는 것이 좋습니다.

$myStr = ("The family of Dashwood had long been settled in Sussex. Their estate was " +
              "large, and their residence was at Norland Park, in the centre of their " +
              "property, where, for many generations, they had lived in so respectable " +
              "a manner as to engage the general good opinion of their surrounding " +
              "acquaintance.")

언급URL : https://stackoverflow.com/questions/31793449/how-to-assign-multiple-lines-string-in-powershell-console