Bash回声多行到文件末尾,但不要在终端回声

时间:2019-02-10 20:46:05

标签: bash macos terminal

我正在编写一个自定义别名函数,以便在我创建新的Web项目时为我创建虚拟主机。在我的函数中,我想将整个新的虚拟主机粘贴到我的Sub AddPivotChart() Dim pivotTbl As PivotTable, ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet2") For Each pivotTbl In ws.PivotTables Dim chtObj As ChartObject Set chtObj = ws.ChartObjects.Add(50, 50, 200, 200) ' adjust as needed chtObj.Name = pivotTbl.Name chtObj.Chart.SetSourceData pivotTbl.TableRange1 Next pivotTbl End Sub 文件中。我首先要输入要创建的域名和文件夹名称

httpd-vhosts.conf

然后在我的函数中,我这样写入read -p 'Please enter the domain for your new site: ' domain; read -p 'Please enter the folder name for your new site: ' folder; 文件

httpd-vhosts.conf

但是我注意到终端和echo " <VirtualHost *:80> ServerAdmin $domain DocumentRoot \"/Users/sam/Development/Websites/$folder\" ServerName $domain ErrorLog \"/usr/local/var/log/httpd/$folder/error_log\" CustomLog \"/usr/local/var/log/httpd/$folder/access_log\" common </VirtualHost>" | sudo tee -a /usr/local/etc/httpd/extra/httpd-vhosts.conf; 文件中都有此回显。该功能可以正常工作,但是如何使其不在终端中回显?

是否需要使用conf以外的其他内容来附加到文件中?

2 个答案:

答案 0 :(得分:2)

只需重定向到/dev/null

echo "
   <VirtualHost *:80>
     ServerAdmin $domain
     DocumentRoot \"/Users/sam/Development/Websites/$folder\"
     ServerName $domain
     ErrorLog \"/usr/local/var/log/httpd/$folder/error_log\"
     CustomLog \"/usr/local/var/log/httpd/$folder/access_log\" common
   </VirtualHost>" | sudo tee -a /usr/local/etc/httpd/extra/httpd-vhosts.conf > /dev/null

这使您可以附加sudo特权,同时也不会在屏幕上显示输出。

答案 1 :(得分:0)

您可以考虑使用tee代替>>

sudo sh -c "echo \"
   <VirtualHost *:80>
     ServerAdmin $domain
     DocumentRoot \"/Users/sam/Development/Websites/$folder\"
     ServerName $domain
     ErrorLog \"/usr/local/var/log/httpd/$folder/error_log\"
     CustomLog \"/usr/local/var/log/httpd/$folder/access_log\" common
   </VirtualHost>\" >> test2.out"