Предоставление данных через именованный трубопровод

Дело не в echo. Речь идет об оболочке. Если вы поищете в man bash, используя, например, эту команду,

man bash | grep -C5 {

вы увидите такое описание

${parameter:offset}
${parameter:offset:length}
       Substring  Expansion.  Expands to up to length characters of the value of parameter starting at the character specified by
       offset.  If parameter is @, an indexed array subscripted by @ or *, or an associative array name, the  results  differ  as
       described below.  If length is omitted, expands to the substring of the value of parameter starting at the character spec‐
       ified by offset and extending to the end of the value.  length and offset are arithmetic expressions (see ARITHMETIC EVAL‐
       UATION below).

echo печатает только подстроку, но printf сделает то же самое.

Все описание в man bash:

${parameter:offset}
${parameter:offset:length}
       Substring Expansion.  Expands to up to length characters of the value
       of parameter starting at  the  character  specified  by  offset.   If
       parameter  is  @, an indexed array subscripted by @ or *, or an asso‐
       ciative array name, the results differ as described below.  If length
       is omitted, expands to the substring of the value of parameter start‐
       ing at the character specified by offset and extending to the end  of
       the  value.  length and offset are arithmetic expressions (see ARITH‐
       METIC EVALUATION below).

       If offset evaluates to a number less than zero, the value is used  as
       an  offset  in characters from the end of the value of parameter.  If
       length evaluates to a number less than zero, it is interpreted as  an
       offset  in  characters  from the end of the value of parameter rather
       than a number of characters, and  the  expansion  is  the  characters
       between  offset and that result.  Note that a negative offset must be
       separated from the colon by at least one space to  avoid  being  con‐
       fused with the :- expansion.

       If  parameter is @, the result is length positional parameters begin‐
       ning at offset.  A negative offset is taken relative to  one  greater
       than  the greatest positional parameter, so an offset of -1 evaluates
       to the last positional parameter.  It is an expansion error if length
       evaluates to a number less than zero.

       If  parameter  is  an  indexed  array name subscripted by @ or *, the
       result is the length members of the array  beginning  with  ${parame‐
       ter[offset]}.   A  negative  offset  is taken relative to one greater
       than the maximum index of the specified array.  It  is  an  expansion
       error if length evaluates to a number less than zero.

       Substring  expansion  applied  to an associative array produces unde‐
       fined results.

       Substring indexing is zero-based unless the positional parameters are
       used,  in  which case the indexing starts at 1 by default.  If offset
       is 0, and the positional parameters are used, $0 is prefixed  to  the
       list.
1
06.05.2017, 20:56
1 ответ

Две вещи:

1) Я применил сон к сценарию внешнего цикла:

for f in /home/sjngm/garage/songstores-*.data; do
  echo "$f..."
  while true; do
    /home/sjngm/shell-scripts/convert.sh "$f" > "$f.m3u"
    sleep 2
  done &
done

2) На случай, если кто-то захочет это сделать: похоже, это не работает. подстановка процесса при попытке записи в именованный канал. Следовательно, здесь помогает старомодный способ использования временных файлов:

#/bin/bash

file="$1"
tmpFile1="/tmp/`uuidgen`"
tmpFile2="/tmp/`uuidgen`"

tail -n +4 "$file" | grep "^#DESCRIPTION" | sed -e 's/#DESCRIPTION /#EXTINF:0,/' > $tmpFile1
tail -n +4 "$file" | grep "^#SERVICE" | cut -d ':' -f 11 | sed -e 's/%3a/:/gi' > $tmpFile2

echo "#EXTM3U"
paste -d '\n' $tmpFile1 $tmpFile2

rm $tmpFile1 $tmpFile2
0
28.01.2020, 00:55

Теги

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