터미널에 붙여넣은 명령이 잘립니다.

터미널에 붙여넣은 명령이 잘립니다.

터미널에 붙여넣고 차례로 실행하려는 명령 목록이 있습니다.

처음에는 잘 작동했지만 명령이 잘렸습니다.

명령 예:

ogr2ogr -nlt PROMOTE_TO_MULTI -progress -skipfailures -overwrite -lco PRECISION=no -f PostgreSQL PG:"dbname='natural_earth' host='localhost' port='5432' user='natural_earth' password='natural_earth'" 50m_physical/ne_50m_lakes.shp

이러한 명령 중 약 150개가 있으며 개행 문자가 꺼진 상태로 gedit에 저장되고 터미널에 블록으로 직접 붙여넣어집니다.

예상되는 결과:

$ ogr2ogr -nlt PROMOTE_TO_MULTI -progress -skipfailures -overwrite -lco PRECISION=no -f PostgreSQL PG:"dbname='natural_earth' host='localhost' port='5432' user='natural_earth' password='natural_earth'" 50m_physical/ne_50m_lakes.shp
0...10...20...30...40...50...60...70...80...90...100 - done.

이는 처음 30개 명령에 대해 작동하며 그 이후에는 명령 잘림 수준이 다릅니다. 예를 들면 다음과 같습니다.

$ ogr2o
ogr2o: command not found

$ ogr
ogr: command not found
$ ogr2ogr -nlt PROMOTE_TO_MULTI -progress -skipfailures -overwrite -lco PRECISION=no -f PostgreSQL PG:"dbname='natural_earth' host='localhost' port='5432' user='natural_earth' password='natural_earth'" 50m_physical/ne_50m_graticules_all/ne_50m_grati

FAILURE:
Unable to open datasource `50m_physical/ne_50m_graticules_all/ne_50m_grati'

그래서 저는 Linux를 처음 접했습니다. gedit에서 복사하여 붙여넣는 것보다 실행하는 더 좋은 방법이 있는지 궁금합니다.

저는 Linux Mint 15 "olivia" Cinnamon 32비트를 실행하고 있습니다.

답변1

실행하려는 명령을 특수 파일에 넣고 쉘 스크립트로 실행하면 됩니다. 인수를 사용하여 셸을 호출하면 다음과 같습니다.

sh your_commands

또는 명령 앞에 추가하십시오.해시본그리고 파일을 실행 가능으로 표시하십시오 chmod a+x your_commands.

#!/bin/sh
your commands
go
here

이렇게 하면 일반 바이너리처럼 작동하고 다음을 실행할 수 있습니다.

 /path/to/your_commands

source또는 현재 셸 내의 파일에서 명령을 실행하는 셸의 기능을 사용할 수 있습니다 (위의 두 셸이 수행하는 작업인 새 셸을 생성하는 대신).

source your_commands

또는

. your_commands

(둘 다 같은 의미입니다.)

답변2

Stack Exchange에 오신 것을 환영합니다. Linux Mint에 오신 것을 환영합니다!

터미널에 붙여넣는 것보다 긴 명령 목록을 실행하는 더 좋은 방법이 있는지 질문하셨습니다. 공교롭게도 명령을 파일에 저장하고 쉘 스크립트로 실행합니다.

예를 들어 명령을 ~/scripts/myscript.sh( ~는 홈 디렉터리의 약어)에 저장하는 경우 다음을 입력하여 실행할 수 있습니다.

# change directory to where the script is
cd ~/scripts
# run the script with bash (most scripts are bash scripts)
bash myscript.sh

작업 디렉토리에 주의하세요

주의할 점: 실행하는 디렉터리가 bash myscript.sh작업 디렉터리로 사용됩니다. 스크립트가 50m_physical/lakes.sh디렉토리의 파일 에 대해 이야기하는 경우 ~/mylakesproject다음이 작동합니다.

cd mylakesproject
bash ~/scripts/myscript.sh
# ~/mylakesproject/50m_physical/lakes.sh exists

이것은 작동하지 않습니다:

cd myotherproject
bash ~/scripts/myscript.sh
# ~/myotherproject/50m_physical/lakes.sh does not exist

이것도 마찬가지입니다:

cd scripts
bash myscript.sh
# ~/scripts/50m_physical/lakes.sh does not exist

행운을 빌고 재미있게 보내!

관련 정보