簡體   English   中英

如何使用換行符作為輸出記錄分隔符從對話框重定向stderr?

[英]How can I redirect stderr from dialog using newlines as the output record separator?

每次我運行命令時,我都希望stderr重定向到/ tmp / test 測試文件應具有用換行符分隔的記錄,而不是轉到同一行。

如果我對選項域名服務器的輸入是192.168.0.1和選項路由器192.168.0.2,則這兩個將在同一行上顯示。 它們應該分開顯示。

我正在使用以下IP地址:

  1. 192.168.0.1
  2. 192.168.0.2

使用以下命令行:

$ dialog --title "Inputbox - Example" \
--inputbox "option domain-name-servers" 8 50 "option domain-name-servers " \
--inputbox "option routers" 8 50 "option routers " \
2> /tmp/test

使用--separate-widget標志

您可以使用--separate-widget標志強制小部件用換行符代替默認的制表符。 例如:

dialog --separate-widget $'\n' \
       --title "Inputbox - Example" \
       --inputbox "option domain-name-servers" 8 50 "option domain-name-servers " \
       --inputbox "option routers" 8 50 "option routers " \
       2> /tmp/test

這是最終代碼。 dhcpd.conf現在將為輸入框的每個輸入提供帶有換行符的正確輸出。

#!/bin/bash

dialog --title "DHCP-CONFIGURATION" \
dialog --separate-widget $'\n' \
--inputbox "option domain-name-servers" 8 50 "option domain-name-servers "
--inputbox "option routers" 8 50 \ "option routers " 
--inputbox "ddns-update-style" 8 50 \ "ddns-update-style"
--inputbox "subnet and netmask" 8 50 \ "subnet and netmask "
--inputbox "range" 8 50 \ "range "
--inputbox "default-lease-time" 8 50 \ "default-lease-time "
--inputbox "max-lease-time" 8 50 \ "max-lease-time "
--inputbox "}" 8 50 \ "} "
2> /tmp/dhcpd.conf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM