Linux'ta dosya içerikleri nasıl çıkartılır ve komut satırı parametreleri olarak iletilir?


0

Bir komut çalıştırmam gerekiyor:

python test.py command --option 1 value1 value2 value3 value4 value5

(değere kadar 100)

Aşağıdaki gibi boşlukla ayrılmış değerleri olan bir metin dosyasına sahibim:

değer1 değer2 değer3 değer4 değer5 ..

Dosya içeriğinin tamamını kopyalayıp terminale yapıştırmadan bunu komuta nasıl aktarabilirim?

Yanıtlar:


4

Bash komutu değiştirme özelliğini kullanabilirsiniz:

python test.py command --option 1 $(<file.txt)

itibaren man bash:

Command substitution allows the output of a command to replace
the command name. There are two forms:

$(command)

or

`command`

Bash performs the expansion by executing command and replacing
the command substitution with the standard output of the command,
with any trailing newlines deleted. Embedded newlines are not
deleted, but they may be removed during word splitting. The
command substitution $(cat file) can be replaced by the
equivalent but faster $(< file).

1

İşte başka bir yol:

xargs -a file.txt python test.py command --option 1

Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.