簡體   English   中英

為什么我不能在bash腳本中添加帶有“ echo >>”的行?

[英]Why I can't add lines with “echo >>” from bash script?

我有代碼:

#!/bin/bash

myParam='/linuxcoe'
myConfigFile='/etc/exports'

if grep -q myParam myConfigFile
  then echo "myParam string exist!"
else
 echo "Did not find string, adding"
 echo "/linuxcoe *" >> myConfigFile
fi

但這在bash腳本中不起作用,在配置中我們沒有換行。 從具有根目錄的控制台回顯“ / linuxcoe *” >> / etc / exports效果很好,但不能從根目錄啟動的腳本運行。 為什么? 怎么解決呢? 如何添加字符串到配置文件?

您的意思是echo "/linuxcoe *" >> "$myConfigFile" 您現有的腳本正在創建一個名為myCOnfigFile的文件。

暫無
暫無

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

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