Разобрать информацию о привязке в переменные, содержащие многострочные данные - PullRequest
0 голосов
/ 23 апреля 2019

Используя bash, я хочу извлечь метаданные, связанные с именами переменных, из запроса на привязку.Приведенный ниже код работает, за исключением двух проблем:

Первая проблема заключается в том, что извлечение информации описания является неполным.Останавливается после двух пустых строк в описании.

Вторая проблема заключается в том, что он не может получить остальные поля после поля описания, кроме идентификатора привязки.

Код:

Package=telegram-desktop
Package_Info=Package_Info.txt
snap info --verbose $Package    > $Package_Info    # Store to avoid multiple fetches from Internet
Snap_name=`cat $Package_Info        | awk '/:/{f=/^name/}f'        | sed 's/: */:/g' | cut -d ":" -f 2`
Snap_summary=`cat $Package_Info     | awk '/:/{f=/^summary/}f'     | sed 's/: */:/g' | cut -d ":" -f 2`
Snap_publisher=`cat $Package_Info   | awk '/:/{f=/^publisher/}f'   | sed 's/: */:/g' | cut -d ":" -f 2`
Snap_contact=`cat $Package_Info     | awk '/:/{f=/^contact/}f'     | sed 's/: */:/g' | cut -d ":" -f 2-3`
Snap_license=`cat $Package_Info     | awk '/:/{f=/^license/}f'     | sed 's/: */:/g' | cut -d ":" -f 2`
Snap_description=`cat $Package_Info | awk '/:/{f=/^description/}f' | sed 's/: */:/g' | cut -d ":" -f 2`
Snap_notes=`cat $Package_Info       | awk '/:/{f=/^notes/}f'       | sed 's/: */:/g' | cut -d ":" -f 2`
Snap_snap_id=`cat $Package_Info     | awk '/:/{f=/^snap-id/}f'     | sed 's/: */:/g' | cut -d ":" -f 2`
Snap_channels=`cat $Package_Info    | awk '/:/{f=/^channels/}f'    | sed 's/: */:/g' | cut -d ":" -f 2`
printf "$Snap_name\n$Snap_summary\n$Snap_publisher\n$Snap_contact\n$Snap_license\n$Snap_description\n$Snap_notes\n$Snap_snap_id\n$Snap_channels\n"

Ввод:

name:      telegram-desktop
summary:   Official desktop client for the Telegram messenger
publisher: Telegram FZ-LLC (telegram.desktop)
contact:   https://github.com/telegramdesktop/tdesktop/issues
license:   GPL-3.0
description: |
  Pure instant messaging — simple, fast, secure, and synced across all your
  devices. Over 100 million active users in two and a half years.

  FAST: Telegram is the fastest messaging app on the market, connecting
  people via a unique, distributed network of data centers around the globe.

  SYNCED: You can access your messages from all your devices at once. Start
  typing on your phone and finish the message from your tablet or laptop.
  Never lose your data again.

  UNLIMITED: You can send media and files, without any limits on their type
  and size. Your entire chat history will require no disk space on your
  device, and will be securely stored in the Telegram cloud for as long as
  you need it.

  SECURE: We made it our mission to provide the best security combined with
  ease of use. Everything on Telegram, including chats, groups, media, etc.
  is encrypted using a combination of 256-bit symmetric AES encryption,
  2048-bit RSA encryption, and Diffie–Hellman secure key exchange.

  POWERFUL: You can create group chats for up to 100,000 members, share large
  videos, documents of any type (.DOC, .MP3, .ZIP, etc.), and even set up
  bots for specific tasks. It's the perfect tool for hosting online
  communities and coordinating teamwork.

  RELIABLE: Built to deliver your messages in the minimum bytes possible,
  Telegram is the most reliable messaging system ever made. It works even on
  the weakest mobile connections.

  FUN: Telegram has powerful photo and video editing tools and an open
  sticker/GIF platform to cater to all your expressive needs.

  SIMPLE: While providing an unprecedented array of features, we are taking
  great care to keep the interface clean. With its minimalist design,
  Telegram is lean and easy to use.

  100% FREE & NO ADS: Telegram is free and will always be free. We are not
  going to sell ads or introduce subscription fees.

  PRIVATE: We take your privacy seriously and will never give third parties
  access to your data.

  We keep expanding the boundaries of what you can do with a messaging app.
  Don’t wait years for older messengers to catch up with Telegram — join the
  revolution today.
notes:         
  private:     false
  confinement: strict
snap-id: jpdoHqMd90M39DdH2JSZbeQxipqHtwLo
channels:
  stable:    1.6.7            2019-04-13 (715) 98MB -
  candidate: ^                                      
  beta:      1.6.6-beta       2019-04-11 (703) 98MB -
  edge:      1.6.7-4-g6f242f2 2019-04-23 (721) 98MB -

Вывод:

telegram-desktop
Official desktop client for the Telegram messenger
Telegram FZ-LLC (telegram.desktop)
https://github.com/telegramdesktop/tdesktop/issues
GPL-3.0
|
Pure instant messaging — simple, fast, secure, and synced across all your
devices. Over 100 million active users in two and a half years.

jpdoHqMd90M39DdH2JSZbeQxipqHtwLo

Как получить данные?

...