$ whatis source
source: nothing appropriate.
$ man source
No manual entry for source
$ source
bash: source: filename argument required
source: usage: source filename [arguments]
Var ve çalıştırılabilir. Neden Ubuntu'da herhangi bir dokümantasyon yok? Bu ne işe yarıyor? Bununla ilgili belgeleri nasıl kurabilirim?
source
/, bağımsız değişken olarak geçirilen dosyanın içeriğini çalıştıran bir bash Kabuğu yerleşik komutudur,geçerli Kabuk'ta. .
(nokta) ile eşanlamlıdır.
Sözdizimi
. filename [arguments] source filename [arguments]
Dikkatli ol! ./
ve source
: tamamen aynı değil .
./script
betiği çalıştırılabilir bir dosya olarak çalıştırır, çalıştırmak için a new Shell komutunu başlatır.source script
, current Shell ortamındaki dosya adındaki komutları okur ve yürütür.Not: ./script
. script
değildir, ancak . script
== source script
'Type' komutunu bilmek faydalıdır:
> type source
source is a Shell builtin
ne zaman bir şey bir Shell yerleşik olduğunda, man bash
.
. (bir dönem), şu anki Shell'de bağımsız değişken olarak geçen bir dosyadan komutları çalıştıran bash Kabuk yerleşik komutudur . 'kaynak', 'için eşanlamlıdır.
Bash adam sayfasından:
. 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.
'kaynak', 'uzun' sürümüdür. Komut. Beşinci Bilgi İsteminde Yapabilecekleriniz:
source ~/.bashrc
geçerli çalışan bash için (değiştirilmiş mi?) bash ayarınızı yeniden yüklemek için.
Kısa versiyon şöyle olurdu:
. ~/.bashrc
Adam sayfa:
. 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
komutu verilen betiği çalıştırır (çalıştırılabilir izin zorunlu değil) geçerli Shell ortamında, ./
verilen çalıştırılabilir betiğini yürütür yeni Kabuğunda.
source
komutu . filename
ile eşanlamlıdır.
Daha açık hale getirmek için, takma adı ayarlayan aşağıdaki betiğe bir göz atın.
#! /bin/bash
alias myproject='cd ~/Documents/Projects/2015/NewProject'
Şimdi bu betiği çalıştırmak için iki seçeneğimiz var. Ancak only one seçeneği ile, mevcut Shell için istenen diğer ad bu iki seçenek arasında oluşturulabilir.
./make_alias
Önce betiği çalıştırılabilir yap.
chmod +x make_alias
./make_alias
alias
**nothing**
Whoops! Takma ad yeni Shell ile birlikte gitti.
İkinci seçenekle gidelim.
source make_alias
source make_alias
veya
. make_alias
alias
alias myproject='cd ~/Documents/Projects/2015/NewProject'
Evet Takma ad ayarlandı.
Şüphe durumunda, yapılacak en iyi şey info
komutunu kullanmaktır:
[[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.
Kabuğunuza "yardım kaynağı" komutunu yazın.
Böyle bir çıktı alacaksınız:
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.
Müthiş bir komut olmasına rağmen, ne source
ne de .
kestirmesinin kaynakbirden fazla dosya anlamına gelmez)
source *.sh
veya
. script1.sh script2.sh
değil işe yarar.
for
loop'larını kullanarak geri dönebiliriz, ancak çalıştırılabilir birçok kez çalıştırılabilir, birden fazla komut oluşturabilir veya sorun çıkarılabilir.
Sonuç: source
, girdi olarak birden fazla dosya almaz. Argüman bir olmalı.
Hangi IMHO'yu berbat eder.
Linux Belgelendirme Projesinden Advanced Bash Scripting Guide,
Bölüm 15 - İç Komutlar ve Yerleşikler :
kaynak ,. (nokta komutu):
Bu komut, komut satırından çağrıldığında bir komut dosyası yürütür. Bir komut dosyasında, bir kaynak dosya adı dosya dosya adını yükler. Bir dosyayı almak (dot-command) betiğe ekleyerek kodu betiğe ekler (bir C programındaki #include direktifiyle aynı etki). Net sonuç, "kaynak kodlu" kod satırlarının kodun gövdesinde fiziksel olarak mevcut olması ile aynıdır. Bu, çoklu komut dosyalarının ortak bir veri dosyası veya işlev kitaplığı kullandığı durumlarda kullanışlıdır.
Kaynak dosyanın kendisi çalıştırılabilir bir komut dosyasıysa, o zaman çalıştırılır, sonra kontrolü çağıran komut dosyasına döndürür. Kaynaklı bir yürütülebilir komut dosyası bu amaç için bir dönüş kullanabilir.
Bu nedenle, C programlama dilini bilenler için, bir dosyanın kaynaklanması #include
yönergesine benzer bir etkiye sahiptir.
Ayrıca, kaynak argümanlara konumsal argümanlar iletebileceğinizi de unutmayın:
$ source $filename $arg1 arg2
Kaynak ile başka bir dosyadaki değişkenleri veya fonksiyonları betiğinize aktarabilir ve tekrar yazmak zorunda kalmadan kullanabilirsiniz.
F.I:
#!/bin/bash
source /etc/environment
source /myscripts/jetty-common/config/jetty-functions.sh
Şerefe