[英]Run commands through Shell Scripts in linux
I'd like to set up a backup.sh
file that executes these two commands when run: 我想设置一个backup.sh
文件,该文件在运行时执行以下两个命令:
cp ~/SURV/plugins/iConomy/accounts.mini ~/backups/
cp ~/SURV/plugins/CoreProtect/database.db ~/backups/
I want it to just run these 2 commands and display the text "Backups creados con éxito!" 我希望它只运行这两个命令并显示文本“ Backups creados conéxito!”。
Use &&
between commands: it will execute the next command only if the previous command execution is a success. 在命令之间使用&&
:仅当上一个命令执行成功时,才会执行下一个命令。 The ||
||
does the inverse => echo "error"
will be displayed if one of the both cp
fails. 如果两个cp
之一都失败,则会显示inverse => echo "error"
。
#!/bin/sh
cp ~/SURV/plugins/iConomy/accounts.mini ~/backups/ &&
cp ~/SURV/plugins/CoreProtect/database.db ~/backups/ &&
echo "Backups creados con éxito!" ||
echo "error"
You can also add -v
option to the cp
command for more visibility. 您还可以在cp
命令中添加-v
选项以提高可见性。
In order to make your script executable you have to do: 为了使脚本可执行,您必须执行以下操作:
chmod +x backup.sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.