developer tip

Windows 명령 프롬프트에서 .sh를 실행하는 방법은 무엇입니까?

optionbox 2020. 8. 9. 10:20
반응형

Windows 명령 프롬프트에서 .sh를 실행하는 방법은 무엇입니까?


Windows 7 명령 프롬프트에서 .sh를 어떻게 실행할 수 있습니까? 이 줄을 실행하려고 할 때 항상이 오류가 발생합니다.

app/build/build.sh

오류,

'app' is not recognized...

또는,

bash app/build/build.sh

오류,

'bash' is not recognized...

내가 놓친 아이디어가 있습니까?

여기 화면 잡기, 여기에 이미지 설명 입력


오류 메시지는 사용자가 설치하지 않았 bash거나 PATH.

Google의 최고 히트작은 http://win-bash.sourceforge.net/ 이지만 대부분의 Bash 스크립트는 Unix와 유사한 환경을 기대한다는 사실을 이해해야합니다. 따라서 Bash를 설치하는 것만으로는이 특정 사용 시나리오를 위해 특별히 설계된 경우가 아니면 인터넷에서 찾은 스크립트를 실행할 수 없을 것입니다. 이에 대한 일반적인 해결책은 https://www.cygwin.com/ 이지만 달성하려는 것이 정확히 무엇인지에 따라 가능한 많은 대안이 있습니다.

Windows가 사용 시나리오의 중심이 아닌 경우 무료 OS (가상화)를 설치하는 것이 가장 간단한 방법 일 수 있습니다.

두 번째 오류 메시지는 Windows가 명목상 슬래시를 디렉터리 구분 기호로 받아들이지 만이 컨텍스트에서는 스위치 구분 기호로 해석되기 때문입니다. 즉, Windows는 명령 줄을 다음과 같이 구문 분석합니다 app /build /build.sh(또는 Unix 옵션 규칙을 사용하여 의역 할 경우 app --build --build.sh). 시도 할 수는 app\build\build.sh있지만 위에 설명 된 상황으로 인해 작동하지 않을 수 있습니다.


GIT를 설치하십시오 . GIT 설치 중에 옵션을 선택하여 Windows 컨텍스트 메뉴에 GIT Bash를 추가하십시오. 설치 후 폴더를 마우스 오른쪽 버튼으로 클릭하고 GIT Bash Here(첨부 된 그림 참조) 예를 들어 sh 명령을 사용하십시오.

sh test.sh

여기에 이미지 설명 입력


The most common way to run a .sh file is using the sh command:

C:\>sh my-script-test.sh 

other good option is installing CygWin

in Windows the home is located in:

C:\cygwin64\home\[user]

for example i execute my my-script-test.sh file using the bash command as:

jorgesys@INT024P ~$ bash /home/[user]/my-script-test.sh 

you can use also cmder

Cmder is a software package created out of pure frustration over the absence of nice console emulators on Windows. It is based on amazing software, and spiced up with the Monokai color scheme and a custom prompt layout, looking sexy from the start

스크린 샷

cmder.net


On Windows 10 Anniversary Update, it's even easier to run shell commands in/with bash on ubuntu on windows

I was trying to set my region for my x-wrt r7000 netgear router, I found the following worked for me, using bash on ubuntu on windows, you do have to enable subsystem found in windows features, and dev mode on

ssh admin@192.168.1.1 < /mnt/c/ccode-eu.sh

New feature in Windows - run bash on ubuntu on windows - available in Windows 10 "Insiders" builds after the Build conference:

https://blogs.windows.com/buildingapps/2016/03/30/run-bash-on-ubuntu-on-windows/


Personally I used this batch file, but it does require CygWin installed (64-bit as shown). Just associate the file type .SH with this batchfile (ExecSH.BAT in my case) and you can double-click on the .SH and it runs.

@echo off
setlocal

if not exist "%~dpn1.sh" echo Script "%~dpn1.sh" not found & goto :eof

set _CYGBIN=C:\cygwin64\bin
if not exist "%_CYGBIN%" echo Couldn't find Cygwin at "%_CYGBIN%" & goto :eof

:: Resolve ___.sh to /cygdrive based *nix path and store in %_CYGSCRIPT%
for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%~dpn1.sh"') do set _CYGSCRIPT=%%A
for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%CD%"') do set _CYGPATH=%%A

:: Throw away temporary env vars and invoke script, passing any args that were passed to us
endlocal & %_CYGBIN%\mintty.exe -e /bin/bash -l -c 'cd %_CYGPATH%;  %_CYGSCRIPT% %*'

Based on this original work.

참고URL : https://stackoverflow.com/questions/26522789/how-to-run-sh-on-windows-command-prompt

반응형