English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
다른 언어와 마찬가지로, Shell도 외부 스크립트를 포함할 수 있습니다. 이렇게 하면 공용 코드를 독립된 파일로 포장하여 쉽게 사용할 수 있습니다.
Shell 파일 포함 문법 형식은 다음과 같습니다:
. filename # note the dot (.) and space between the dot and the filename 또는 source filename
두 개의 shell 스크립트 파일을 생성합니다。
test1.sh 코드는 다음과 같습니다:
#!/bin/bash # author:기본 튜토리얼 웹사이트 # url:ko.oldtoolbag.com url="http://ko.oldtoolbag.com"
test2.sh 코드는 다음과 같습니다:
#!/bin/bash # author:기본 튜토리얼 웹사이트 # url:ko.oldtoolbag.com #use . number to refer to test1.sh 파일 . ./test1.sh # 또는 다음 포함 파일 코드를 사용합니다 # source ./test1.sh echo "기본 튜토리얼 웹사이트 주소: $url"
다음은 test에2.sh에 실행 권한 추가하고 실행하세요:
$ chmod +x test2.sh $ ./test2.sh 기본 튜토리얼 웹사이트 주소: http://ko.oldtoolbag.com
주의:포함된 파일 test1.sh는 실행 권한이 필요하지 않습니다。