Bash Loop Все файлы в каталоге, затем строки петли каждого файла

Эта команда, вероятно, то, что вы ищете:

lsb_release -a

Поскольку lsb означает 'Linux Standard Base', разумно ожидать, что она будет присутствовать.

http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/lsbrelease.html

-6
14.01.2019, 21:49
1 ответ

Чтобы ответить на ваш вопрос, как написано, вы можете сделать следующее:

#!/bin/bash

for file in /path/to/files/*.txt; do
    # This will loop through each.txt file in the directory
    # setting the full file path to $file
    # I recommend adding the.txt if you know all your files
    # will have that extension otherwise the following is fine:
    # for file in /path/to/files/*; do
    while read -r line; do
        # This will loop through each line of the current file
        # and set the full line to the $line variable
        command "$line"
    done < "$file"
done

Пояснения в комментариях внутри кода

1
28.01.2020, 05:21

Теги

Похожие вопросы