shell - how to use the if statement for error and warning messages in bash -
i writing codes on gedit , want latest error , warning messages using if statement, if theres error should warning messages.
cp /volumes/documents/criticalfile.txt /volumes/backup/. if [ "?" != 0 ]; echo "[error] copy failed!" 1>&2 exit 1 fi
i've used above code not sure if correct or not.
you have use
if [ "$?" != 0 ];
instead of
if [ "?" != 0 ];
let want copy file don't know if error. use below command
cp -f /root/desktop/my_new_file */root/t
definitely give me error because copying "*/root/t" not possible.
i can check using following codes
#!/bin/bash cp -f /root/desktop/my_new_file */root/t if [ "$?" = 0 ];then echo "no error" else echo "we have error!" fi
my output (note condition working)
cp: cannot create regular file `*/root/t': no such file or directory have error
now let want copy file possible location like
cp -f /root/desktop/my_new_file /root/t
i no error cp command
output
no error
Comments
Post a Comment