Yanıtlar:
$(command)Sözdizimi çıktısını dönecektir command. Burada, cattek işi standart girdiden (stdin) standart çıktıya (stdout) kopyalamak olan çok basit bir program kullanıyorsunuz . Çalıştırdığınız yana awkçift tırnak içine senaryoyu, $(cat)kabuk tarafından genişletilir önceawk komut çalıştırılır okur, böylece echoonun Stdin ve Stdout'a usulüne kopya o içine çıktı. Bu daha sonra awkkomut dosyasına aktarılır . Bunu çalışırken aşağıdakilerle görebilirsiniz set -x:
$ set -x
$ echo '((3+(2^3)) * 34^2 / 9)-75.89' | awk "BEGIN{ print $(cat) }"
+ echo '((3+(2^3)) * 34^2 / 9)-75.89'
++ cat
+ awk 'BEGIN{ print ((3+(2^3)) * 34^2 / 9)-75.89 }'
1337
Yani, 1337 döndüren awkaslında çalışıyor BEGIN{ print ((3+(2^3)) * 34^2 / 9)-75.89 }'.
Şimdi, $*bir kabuk betiğine verilen tüm konumsal parametrelere genişleyen özel bir kabuk değişkeni (bkz. man bash):
* Expands to the positional parameters, starting from one. When the expan‐
sion is not within double quotes, each positional parameter expands to a
separate word. In contexts where it is performed, those words are sub‐
ject to further word splitting and pathname expansion. When the expan‐
sion occurs within double quotes, it expands to a single word with the
value of each parameter separated by the first character of the IFS spe‐
cial variable. That is, "$*" is equivalent to "$1c$2c...", where c is
the first character of the value of the IFS variable. If IFS is unset,
the parameters are separated by spaces. If IFS is null, the parameters
are joined without intervening separators.
Ancak, bu değişken burada boştur. Bu nedenle, awkkomut dosyası olur:
$ echo '((3+(2^3)) * 34^2 / 9)-75.89' | awk "BEGIN{ print $* }"
+ awk 'BEGIN{ print }'
+ echo '((3+(2^3)) * 34^2 / 9)-75.89'
$*Boş bir dizeye genişler ve awkboş bir dize yazdırmak için söylenir ve hiçbir çıkış almak bu yüzden.
Bunun bcyerine sadece şunu kullanmak isteyebilirsiniz :
$ echo '((3+(2^3)) * 34^2 / 9)-75.89' | bc
1336.11
scale=(OP'nin leetspeak ile oynamak istediğini varsayıyorum) ama bir yol bulamadım. sistemime bc -lgeri döner 1336.99888888888888888888.
bc -l, aksi takdirde yukarıda paylaştığınız tutarsızlığı elde edersiniz (bölümün sonucunun kesildiği yer).