Carrot in DOS Command
캐럿(^) 문자는 이스케이프문자로 이미 특정용도로 사용되는 문자를 인터프리트 없이 단순문자로 인식하도록 하는 이스케이프 문자이다. 쌍따옴표 같은 경우에는 ��와 같이 두 번 사용하므로해서 출력을 � 로 표현할 수 있다. 섹션 2에서는 간단히 Wifi 패스워드를 보여주는 배치파일을 이용해서 캐럿문자를 어떻게 사용하는 지 보여준다.
netsh wlan show profile name^="%ssid:"=%" key^=clear ^| findstr
/C:"Key Content"
In the command you provided, the caret (^) is used to escape the special characters "=" and "|" within the command. Without the caret, these characters would have special meanings in the command prompt and would affect the execution of the command.
아래 간단한 예를 보라.
� `^=`: This is used to escape the "=" character, indicating that it should be treated as a literal character rather than as an assignment operator.
� `^|`: This is used to escape the "|" character, indicating that it should be treated as a literal character rather than as a pipe operator.
rem to find password from the aps in your site @echo off rem @echo off setlocal enabledelayedexpansion for /f "tokens=2 delims=:" %%a in ('netsh wlan show profile ^|findstr ":"') do ( set "ssid=%%~a" call :getpwd "!ssid:~1!" ) :getpwd set "ssid=%*" for /f "tokens=2 delims=:" %%i in ('netsh wlan show profile name^="%ssid:"=%" key^=clear ^| findstr /C:"Key Content"') do echo ssid: !ssid! pass: %%i
|
배치파일에서는 !는 특수문자에 해당한다. 특히 지연된 확장을 사용하게 될 때 사용되며 실행 중 그 내용이 결정된다.
1. **Using Caret (^) Escape Character**: You can use the caret (`^`) escape character to display the exclamation mark without issues.
��� ```batch
��� echo ^!
��� ```
2. **Using Double Exclamation Marks**: Another way is to use double exclamation marks `!!`, as the second one will be treated as a literal exclamation mark.
��� ```batch
��� echo !!
��� ```
3. **Disabling Delayed Expansion (For More Complex Cases)**: If you're dealing with more complex situations and don't want to worry about delayed expansion, you can temporarily disable it.
��� ```batch
��� @echo off
��� setlocal DisableDelayedExpansion
��� echo !
��� endlocal
��� ```