Linux脚本——sed字段替换和get_char()暂停函数的使用
#!/bin/bash # 暂停函数,用于人为介入判断 get_char() { SAVEDSTTY=`stty -g` stty -echo stty cbreak dd if=/dev/tty bs=1 count=1 2> /dev/null stty -raw stty echo stty $SAVEDSTTY } # echo " Hello, the world is very beautiful! " > sed_test.txt echo " Hello, the world is very beautiful! " >> ./logs/sed_test.txt # 替换文本中的字符串 # sed -i "s/Hello, the world is very beautiful!/Hell0, the w0rld is very beautiful!/g" ./sed_test.txt # 替换每行中的空格为空 sed 's/ //g' ./logs/sed_test.txt >> ./logs/sed_result.txt echo . >> ./logs/sed_result.txt char=`get_char` rm -rf ./logs/sed_test.txt
稳步前行,只争朝夕。