$ whatis source
source: nothing appropriate.
$ man source
No manual entry for source
$ source
bash: source: filename argument required
source: usage: source filename [arguments]
إنه موجود ، وهو قابل للتشغيل. لماذا لا يوجد أي وثائق حول هذا الموضوع في أوبونتو؟ ماذا تعمل، أو ماذا تفعل؟ كيف يمكنني تثبيت وثائق حول هذا الموضوع؟
source
هو أمر bash Shell مضمن ينفذ محتوى الملف الذي تم تمريره كوسيطة ،في Shell الحالي. له مرادف في .
(الفترة).
بناء الجملة
. filename [arguments] source filename [arguments]
كن حذرا! ./
و source
هي ليست متطابقة تمامًا .
./script
على تشغيل البرنامج النصي كملف قابل للتنفيذ ، حيث يقوم بتشغيل Shell جديد لتشغيلهsource script
يقرأ وينفذ الأوامر من اسم الملف في Shell الحالي البيئةملاحظة: ./script
ليس . script
، ولكن . script
== source script
من المفيد معرفة الأمر "type":
> type source
source is a Shell builtin
كلما كان هناك شيء مدمج في Shell ، فقد حان الوقت للقيام بـ man bash
.
. (فترة) هي أمر مدمج bash Shell ينفذ الأوامر من ملف تم تمريره كوسيطة ، في Shell الحالي. "المصدر" مرادف لـ ".".
من صفحة رجل باش:
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current Shell
environment and return the exit status of the last command exe‐
cuted from filename. If filename does not contain a slash, file
names in PATH are used to find the directory containing file‐
name. The file searched for in PATH need not be executable.
When bash is not in posix mode, the current directory is
searched if no file is found in PATH. If the sourcepath option
to the shopt builtin command is turned off, the PATH is not
searched. If any arguments are supplied, they become the posi‐
tional parameters when filename is executed. Otherwise the
positional parameters are unchanged. The return status is the
status of the last command exited within the script (0 if no
commands are executed), and false if filename is not found or
cannot be read.
"المصدر" هو الإصدار الطويل من "." أمر. على باش موجه واحد يمكن أن يفعله:
source ~/.bashrc
لإعادة تحميل (bash؟) إعداد bash لـ bash الحالي.
نسخة قصيرة ستكون:
. ~/.bashrc
صفحة الرجل:
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current Shell environment and
return the exit status of the last command executed from filename. If
filename does not contain a slash, file names in PATH are used to find the
directory containing filename. The file searched for in PATH need not be
executable. When bash is not in posix mode, the current directory is
searched if no file is found in PATH. If the sourcepath option to the short
builtin command is turned off, the PATH is not searched. If any arguments
are supplied, they become the positional parameters when filename is
executed. Otherwise the positional parameters are unchanged. The return
status is the status of the last command exited within the script (0 if no
commands are executed), and false if filename is not found or cannot be
read.
ينفذ أمر source
البرنامج النصي المتوفر (إذن قابل للتنفيذ هو {غير إلزامي) في بيئة شل {الحالية بينما ينفذ ./
النص المتوفر قابل للتنفيذ البرنامج النصي في جديد Shell.
يوجد أمر مرادف source
. filename
.
لجعلها أكثر وضوحًا ، ألقِ نظرة على البرنامج النصي التالي ، الذي يحدد الاسم المستعار.
#! /bin/bash
alias myproject='cd ~/Documents/Projects/2015/NewProject'
الآن لدينا خياران لتنفيذ هذا البرنامج النصي. ولكن مع فقط خيار واحد ، يمكن إنشاء الاسم المستعار المطلوب لـ Shell الحالي بين هذين الخيارين.
./make_alias
اجعل البرنامج النصي قابلاً للتنفيذ أولاً.
chmod +x make_alias
./make_alias
alias
**nothing**
(عفوًا! الاسم المستعار ذهب مع شركة شل الجديدة.
دعنا نذهب مع الخيار الثاني.
source make_alias
source make_alias
أو
. make_alias
alias
alias myproject='cd ~/Documents/Projects/2015/NewProject'
(نعم تم تعيين الاسم المستعار.
عندما تكون في شك ، فإن أفضل شيء يمكنك فعله هو استخدام الأمر info
:
[[email protected] ~]# info source
BASH BUILTIN COMMANDS
Unless otherwise noted, each builtin command documented in this section
as accepting options preceded by - accepts -- to signify the end of the
options. The :, true, false, and test builtins do not accept options
and do not treat -- specially. The exit, logout, break, continue, let,
and shift builtins accept and process arguments beginning with - with-
out requiring --. Other builtins that accept arguments but are not
specified as accepting options interpret arguments beginning with - as
invalid options and require -- to prevent this interpretation.
: [arguments]
No effect; the command does nothing beyond expanding arguments
and performing any specified redirections. A zero exit code is
returned.
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current Shell
environment and return the exit status of the last command exe-
cuted from filename. If filename does not contain a slash, file
names in PATH are used to find the directory containing file-
name. The file searched for in PATH need not be executable.
When bash is not in posix mode, the current directory is
searched if no file is found in PATH. If the sourcepath option
to the shopt builtin command is turned off, the PATH is not
searched. If any arguments are supplied, they become the posi-
tional parameters when filename is executed. Otherwise the
positional parameters are unchanged. The return status is the
status of the last command exited within the script (0 if no
commands are executed), and false if filename is not found or
cannot be read.
اكتب الأمر "مصدر التعليمات" في Shell الخاص بك.
سوف تحصل على الإخراج مثل هذا:
source: source filename [arguments]
Execute commands from a file in the current Shell.
Read and execute commands from FILENAME in the current Shell. The
entries in $PATH are used to find the directory containing FILENAME.
If any ARGUMENTS are supplied, they become the positional parameters
when FILENAME is executed.
Exit Status:
Returns the status of the last command executed in FILENAME; fails if
FILENAME cannot be read.
تجدر الإشارة إلى أنه على الرغم من كونه أمرًا رائعًا ، فإن source
ولا اختصارها لـ .
سوف source أكثر من =ملف ، يعني
source *.sh
أو
. script1.sh script2.sh
سوف لاالعمل.
يمكننا التراجع عن استخدام حلقات for
، لكن ذلك سيصدر الملف القابل للتنفيذ عدة مرات ، مما يؤدي إلى إنشاء أوامر أو مشكلة متعددة.
الخلاصة: source
لا يأخذ ملفات متعددة كمدخلات. يجب أن تكون الحجة واحدة.
والتي تمتص IMHO.
من مشروع وثائق Linux ، دليل البرمجة المتقدمة للباش ،
الفصل 15 - الأوامر الداخلية والمحتويات :
المصدر ،. (نقطة نقطة):
هذا الأمر ، عندما يتم استدعاؤه من سطر الأوامر ، ينفذ برنامج نصي. داخل البرنامج النصي ، يقوم اسم الملف المصدر بتحميل اسم الملف. تحديد مصدر ملف (dot-command) باستيراد الكود في البرنامج النصي ، إلحاق البرنامج النصي (نفس التأثير مثل توجيه #include في برنامج C). النتيجة الصافية هي نفسها كما لو كانت الأسطر "المصدر" من الكود موجودة فعليًا في نص البرنامج النصي. يعد هذا مفيدًا في الحالات التي تستخدم فيها برامج نصية متعددة ملف بيانات أو مكتبة وظائف شائعة.
إذا كان الملف المصدر هو نفسه برنامج نصي قابل للتنفيذ ، فسيتم تشغيله ، ثم يُرجع التحكم إلى البرنامج النصي الذي يطلق عليه. قد يستخدم البرنامج النصي القابل للتنفيذ المصدر مصدرًا لهذا الغرض.
لذلك ، بالنسبة لأولئك المطلعين على لغة البرمجة C ، فإن تحديد مصدر ملف له تأثير مماثل لتوجيهات #include
.
لاحظ أيضًا أنه يمكنك تمرير وسيطات موضعية إلى الملف الذي يتم تحديد مصدره ، مثل:
$ source $filename $arg1 arg2
باستخدام المصدر ، يمكنك تمرير المتغيرات أو الوظائف من ملف آخر إلى البرنامج النصي واستخدامها دون الحاجة إلى كتابتها مرة أخرى.
F.I:
#!/bin/bash
source /etc/environment
source /myscripts/jetty-common/config/jetty-functions.sh
في صحتك