在BASH中保存editbox中的文件内容
我想学习shell脚本。我想创建一个简单的工具,用编辑选项显示文件内容,但我无法从在BASH中保存editbox中的文件内容,bash,shell,dialog,Bash,Shell,Dialog,我想学习shell脚本。我想创建一个简单的工具,用编辑选项显示文件内容,但我无法从对话框--editbox中获取值。谁能解释一下它是怎么工作的 我的代码: #!/bin/bash BACKTITLE="Some backtitle" FILENAME="filename.txt" touch $FILENAME INPUT=/tmp/menu.sh.$$ ret=0 while [ $ret -eq 0 ] do dialog --title "Menu" \ -
对话框--editbox
中获取值。谁能解释一下它是怎么工作的
我的代码:
#!/bin/bash
BACKTITLE="Some backtitle"
FILENAME="filename.txt"
touch $FILENAME
INPUT=/tmp/menu.sh.$$
ret=0
while [ $ret -eq 0 ]
do
dialog --title "Menu" \
--backtitle "$BACKTITLE" \
--menu "Wybierz" 10 60 3 \
1 "Pokaz menu" \
2 "Edytuj" \
2>"${INPUT}"
ret=$?
option=$(<"${INPUT}")
if [ $ret -eq 0 ]
then
if [ $option -eq 1 ]
then
dialog --title "File content" \
--backtitle "$BACKTITLE" \
--textbox $FILENAME 10 60
elif [ $option -eq 2 ]
then
dialog --title "Edit file content" \
--backtitle "$BACKTITLE" \
--editbox $FILENAME 10 60
editboxret=$?
echo $editboxret
ret=0
fi
fi
done
#/bin/bash
BACKTITLE=“一些BACKTITLE”
FILENAME=“FILENAME.txt”
触摸$FILENAME
输入=/tmp/menu.sh$$
ret=0
而[$ret-等式0]
做
对话框--标题“菜单”\
--backtitle“$backtitle”\
--菜单“Wybierz”10 60 3\
1“Pokaz菜单”\
2“Edytuj”\
2> “${INPUT}”
ret=$?
option=$(对话框将“已编辑”的内容写入STDERR,您需要确保它再次出现在原始文件中
# Write the output of dialog to a temp-file
dialog --editbox $FILENAME 10 60 2> "${INPUT}"
# ADVISED: Show the user the temporary file-content
# and ask for confirmation before doing the next step:
# Overwrite the input-file
cp ${INPUT} $FILENAME
根据手册页(man对话框
),输出将写入stderr。
使用中的建议,您可以使用
{ newcontents=$(dialog --title "Edit file content" -- backtitle "$BACKTITLE" --editbox $FILENAME 10 60 2>&1 1>&$out); } {out}>&1
@沃尔特:说得好,我错过了手册中说它是写给斯特德的部分。:-)