2014-01-23 53 views
0

這是我的代碼:如何使用bash存儲編輯過的文本文件?

Edit_Record(){

zenity --width=600 --height=300 --text-info --title="Records" --filename=$FILE --editable 
    if [ "$?" = 0 ]; then 
      kdialog --title "Saving the Data" --warningyesnocancel "Do you want to save the changes?" 
      if [ "$?" = 0 ]; then 
      kdialog --msgbox "The changes have been added!" 

      Home; 

      elif [ "$?" = 1 ]; then 
      kdialog --msgbox "No changes has been added!" 
      Home; 

      else 
      Home; 

      fi; 

    else 

    zenity --info --text "You chose to Cancel." 
    exit 
    fi; 
} 

我不知道該怎麼把後面「kdialog --msgbox 「已添加的變化」 :( 請幫助

+0

混合zenity和kdialog?爲什麼? – choroba

+0

只是想在一次編程中體驗不同的gui's – Furabells

回答

1

zenity --editable返回編輯的文本到標準輸出。你可以把它保存到重定向的臨時文件,如果用戶想要保存更改,只需將臨時文件在原始。

tmp=$(mktemp) 
zenity --editable ... > $tmp 

if ... ; then 
    mv $FILE "$FILE"~ 
    mv $tmp "$FILE" 
fi 
+0

我會試試這個,謝謝! – Furabells

+0

它工作!超級謝謝你! :D – Furabells

+0

@Furabells:沒問題:-)只是upvote和/或接受答案... – choroba