기본 콘텐츠로 건너뛰기

글

라벨이 파워쉘인 게시물 표시

PSReadLine 설치

* Powershell 7 부터는 PSReadLine 기본 설치 및 기본 로딩 참조: PSReadLine # 설치 Install-Module -Name PSReadLine -AllowClobber -Force # 예측 사용 Set-PSReadLineOption -PredictionSource History 참조: 히스토리 제한 # 히스토리 개수 제한 Set-PSReadlineOption -MaximumHistoryCount 100 -HistoryNoDuplicates # 3글자 초과만 히스토리에 남김 Set-PSReadlineOption -AddToHistoryHandler { param([string]$line) return $line.Length -gt 3 }

Powershell Array, Map 정리

Powershell에서 Array, Map에 대한 정리. (매번 찾기 귀찮) 참조: Bash Array, Map 정리 Array 참조:  배열에 대해 알고 싶은 모든 것 # 생성 $empty_array = @() $ar = @("haha", "hoho", "baba", "long string haha hoho") # $ar = "hello", "world, "byebye" # 접근 Write-Output "`$ar[0]=$($ar[0])" Write-Output "all as array=$($ar)" # 기본 Write-Output "all as one=$($ar -join ' ')" # 띄어쓰기를 포함하여 문자열로 합치기 Write-Output "all as one=$(-join $ar)" # 띄어쓰기 없이 문자열로 합치기 Write-Output "length=$($ar.Count)" Write-Output "last=$($ar[-1])" # 현재 상황 Write-Output $ar $ar[-1] = "last" Write-Output $ar # 마지막 원소를 지우고 대입한다. $ar[-2] = "whoami" Write-Output $ar # 마지막-1 원소를 지우고 대입한다. # 추가 $ar += @("blar") $ar += @("keke", "123", "456") $ar += @("long long long string", "another long long long string") Write-Output $ar # Powershell은 Array에 대해 삭제를...

PowerShell 시작 스크립트 위치

Command.com 그리고 cmd.exe를 거쳐 PowerShell.exe 시대가 온 지 오래지만, 그다지 흥미가 없다. 그래도 울며 겨자 먹기 식으로 써야할 때가 있어 쓰는데, bash처럼 .bash_profile, .profile 시작 스크립트가 있으면 좋을꺼 같아 찾아 보았다. bash+awk 같은 걸로 손쉽게 얻어낼 수 있는 값이 있긴 한데, cmd.exe나 PowerShell에선 레지스트리 값을 읽어와 파싱하고 어찌고 저찌고 하는데, 사실 귀찮다. 위치는 "문서" 폴더 아래 "WindowsPowerShell" 폴더이고, 스크립트 이름은 profile.ps1이다. 대충 적어 보자면... REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal 여기서 나온 디렉토리에 "\WindowsPowerShell\profile.ps1"을 붙이면 끝. == 2020년 4월 17일 추가 Core6부터 위와 같이 어렵게 할 필요 없다. $PROFILE 변수에 시작 스크립트 풀패스가 적혀 있다. vi $PROFILE 참조:  https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7