shell – 验证副本是否成功
发布时间:2020-12-16 01:14:56 所属栏目:安全 来源:网络整理
导读:我想编写一个脚本来验证副本是否成功. 这就是我所拥有的: #!/bin/shcp home/testing/present.txt home/testing/future.txt echo "Copy Code: $? - Successful"if [ $? != 0 ]; then echo "Copy Code: $? - Unsuccessful"fi “if”语句未初始化.怎么解决这个
我想编写一个脚本来验证副本是否成功.
这就是我所拥有的: #!/bin/sh cp home/testing/present.txt home/testing/future.txt echo "Copy Code: $? - Successful" if [ $? != 0 ]; then echo "Copy Code: $? - Unsuccessful" fi “if”语句未初始化.怎么解决这个?
$?指的是最后一个命令:
#!/bin/sh cp home/testing/present.txt home/testing/future.txt echo "Copy Code: $? - Successful" # last command: cp if [ $? != 0 ]; then # last command: echo echo "Copy Code: $? - Unsuccessful" # last command: [ fi 如果要重复使用特定命令的状态,只需将结果保存在另一个变量中: #!/bin/sh cp home/testing/present.txt home/testing/future.txt status=$? echo "Copy Code: $status - Successful" if [ $status != 0 ]; then echo "Copy Code: $status - Unsuccessful" fi 但是,更好的方法是首先简单地测试cp命令: if cp home/testing/present.txt home/testing/future.txt then echo "Success" else echo "Failure,exit status $?" fi (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容