반응형
powershell: 문자열을 평가하는 방법
내파일a.txt포함 내용:
delete from test_$suffix
My PowerShell은 다음과 같습니다.
$a = get-content a.txt
$suffix = "tableA"
내가 어떻게 조작하겠습니까?$a끈을 얻다delete from test_tableA?
$a=get-content a.txt
$suffix="tableA"
$ExecutionContext.InvokeCommand.ExpandString($a)
Invoke-Expression이 동치입니다.
$strExpression = "5 + 5 -eq 10"
Invoke-Expression $strExpression
True
자세한 정보는 http://technet.microsoft.com/en-us/library/ee176880.aspx 을 참조하십시오.
한가지 방법이 있습니다.이중 따옴표가 있는 여기 문자열의 변수는 자동으로 대체됩니다.입력 파일이 여기 문자열에 대한 PS 규칙을 준수하는지 확인하십시오.
function convertto-herestring {
begin {$temp_h_string = '@"' + "`n"}
process {$temp_h_string += $_ + "`n"}
end {
$temp_h_string += '"@'
iex $temp_h_string
}
}
$suffix = "tableA"
get-content testfile.txt
delete from test_$suffix
get-content testfile.txt | convertto-herestring
delete from test_tableA
언급URL : https://stackoverflow.com/questions/4836703/powershell-how-to-evaluate-a-string
반응형
'programing' 카테고리의 다른 글
| jQuery "정의되지 않은 속성 'defaultView'를 읽을 수 없습니다" 오류 (0) | 2023.09.09 |
|---|---|
| 스프링 부트 페일 세이프 청소(집합)가 발생하는 이유 (0) | 2023.09.09 |
| HTML5 범위 입력을 슬라이더 전후로 다른 색상으로 스타일화하는 방법은? (0) | 2023.09.09 |
| URL에 가장 적합한 열 유형은 무엇입니까? (0) | 2023.09.09 |
| 주문 기준을 사용한 Mariaadb 증분 카운터 (0) | 2023.09.09 |