我对 shell 脚本完全陌生,但我需要编写一个 shell 脚本来检查文件是否存在,然后移动到另一个位置
这是我写的:
一旦设备崩溃,我就会在/storage/sdcard1/1 中收集日志
#!/system/bin/sh
if [ -d /storage/sdcard1/1 ]; then
mkdir crash1
mv 1 crash1
fi
无论我们找到/storage/sdcard1/1 目录,我们都必须分别将其重命名为 crash1,crash2,crash3
。
我无法理解其中的逻辑。谁能帮我吗?
最佳答案
target=/home/john/data
if [ -d /storage/sdcard1/1 ]; then
mv /storage/sdcard1/1 $target/crash1
fi
将目标设置为您想要“crash1”的位置 重复代码,用 2 和 3 代替 1
大多数人会使用变量和循环来执行 1,2,3,但让我们保持简单
关于linux - 用于重命名文件的 Shell 脚本 - Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28747409/