UNIX'te [email protected]
ve $*
arasındaki fark nedir? Bir senaryoda yankılandığında, her ikisi de aynı çıktıyı üretir.
14
A
cevap
5
farklardan biri de çıkışını IFS değişkeni nasıl ele içindedir.
#!/bin/sh
echo "unquoted asterisk " $*
echo "quoted asterisk $*"
echo "unquoted at " [email protected]
echo "quoted at [email protected]"
IFS="X"
echo "IFS is now $IFS"
echo "unquoted asterisk " $*
echo "quoted asterisk $*"
echo "unquoted at " [email protected]
echo "quoted at [email protected]"
böyle bu çalıştırırsanız: ./demo abc def ghi
, bu çıktıyı almak:
IFS
ardından gelen her "kelime" arasında bir X gösteren Bildirimi o
unquoted asterisk abc def ghi
quoted asterisk abc def ghi
unquoted at abc def ghi
quoted at abc def ghi
IFS is now X
unquoted asterisk abc def ghi
quoted asterisk abcXdefXghi
unquoted at abc def ghi
quoted at abc def ghi
"X" olarak değiştirildi. IFS
'un değeri birden çok karakter içeriyorsa, bu amaçla yalnızca ilk karakter kullanılır. Bu özellik
$ array=(123 456 789)
$ saveIFS=$IFS; IFS="|"
$ echo "${array[*]}"
123|456|789
$ IFS=$saveIFS
13
Lütfen Özel Parametreler altındaki bash man sayfasına bakın.
Special Parameters
The shell treats several parameters specially. These parameters may
only be referenced; assignment to them is not allowed.
* Expands to the positional parameters, starting from one. When
the expansion occurs within double quotes, it expands to a sin‐
gle word with the value of each parameter separated by the first
character of the IFS special variable. That is, "$*" is equiva‐
lent to "$1c$2c...", where c is the first character of the value
of the IFS variable. If IFS is unset, the parameters are sepa‐
rated by spaces. If IFS is null, the parameters are joined
without intervening separators.
@ Expands to the positional parameters, starting from one. When
the expansion occurs within double quotes, each parameter
expands to a separate word. That is, "[email protected]" is equivalent to "$1"
"$2" ... If the double-quoted expansion occurs within a word,
the expansion of the first parameter is joined with the begin‐
ning part of the original word, and the expansion of the last
parameter is joined with the last part of the original word.
When there are no positional parameters, "[email protected]" and [email protected] expand to
nothing (i.e., they are removed).
2
O "[email protected]"
yerine $*
kullanmak güvenlidir. Çoklu komut dizilerini bir kabuk komut dosyasına argüman olarak kullandığınızda, yalnızca her bir bağımsız değişkeni ayrı bir argüman olarak yorumlayan "[email protected]"
olur.
Yukarıdaki çıktı öneriyorsa, $*
kullanırsanız, kabuk bağımsız değişkenlerin sayısını sayar.
2
for i in "[email protected]"
do
echo $i # loop $# times
done
for i in "$*"
do
echo $i # loop 1 times
done
İlgili konular
- 1. Python'da {} ve [] arasındaki fark nedir?
- 2. $ arasındaki fark nedir? ve PowerShell
- 3. Fark() arasındaki fark nedir mustache.js
- 4. arasındaki fark nedir?
- 5. Java arasındaki fark nedir
- 6. arasındaki fark nedir?
- 7. arasındaki fark nedir?
- 8. app.doScript ve $ .evalFile arasındaki fark nedir?
- 9. gVim ve gVim arasındaki fark nedir?
- 10. isAlpha ve isLetter arasındaki fark nedir?
- 11. Control.Enter ve Control.GotFocus olayları arasındaki fark nedir?
- 12. .got ve .got.plt bölümü arasındaki fark nedir?
- 13. AutomationProperties.AutomationID ve AutomationProperties.Name arasındaki fark nedir?
- 14. Android'de getDir ve getFilesDir arasındaki fark nedir?
- 15. R içinde `=` ve `<-` arasındaki fark nedir?
- 16. uint ve System.UInt32 arasındaki fark nedir?
- 17. PropertyChangeListener ve VetoableChangeListener arasındaki fark nedir?
- 18. XSS'de IDREF ve IDREFS arasındaki fark nedir?
- 19. Cacerts ve keystore arasındaki fark nedir?
- 20. GPLv2 ve GPLv3 arasındaki fark nedir?
- 21. VarIsEmpty ve VarIsEmptyParam işlevleri arasındaki fark nedir
- 22. ActiveSupport'ta mattr_accessor ve cattr_accessor arasındaki fark nedir?
- 23. Hashtable ve Dictionary arasındaki fark nedir?
- 24. RoutedCommand ve RoutedUICommand arasındaki fark nedir?
- 25. MySQL'deki boolean ve bool arasındaki fark nedir?
- 26. Task.Factory.FromAsync ve BeginX/EndX arasındaki fark nedir?
- 27. WideChar ve AnsiChar arasındaki fark nedir?
- 28. PHP'de 'stripcslashes' ve 'stripslashes' arasındaki fark nedir?
- 29. AxInterop ve Interop arasındaki fark nedir?
- 30. MsBuild'de, CreateProperty ve PropertyGroup arasındaki fark nedir?
bakınız [Bir bash komut argümanlar üzerinde yineleme yöntemi] (http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script/256225# 256.225). Bu cevap, $ @ 've' $ * 'arasındaki farklılıkları (soru olmasa bile) açıkça kapsar. En önemli fark, teklif altındaki davranışlarda - "$ *" ve "$ @" arasındaki farktır. –