Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正如标题所说。我需要能够备份然后恢复文件。
进行备份非常简单
if [ "$bup" = "true" ]; then cp $file $file.bak
但要实现复苏……并不是那么直截了当。
elif [ "$rup" = "true" ]; then bak=`find /path/to/file/ | grep .bak` cp $bak ${bak/\.bak} fi
它在 bash 中工作,但我需要它在 sh 中工作。
bash shell 参数扩展在 sh 中不起作用。试试这个:
elif [ "$rup" = "true" ]; then bak=`find /path/to/file/ | grep .bak` orig=`echo $bak | sed 's/\.bak$//'` cp $bak $orig fi
如果您打算处理多个 .bak 文件,请不要忘记在 find 输出周围添加一个循环。
使用子字符串处理而不是正则表达式变体:
orig=${bak%.bak}