bash script help?
Knute Johnson
ubuntu at knutejohnson.com
Mon Nov 14 17:10:47 UTC 2011
On 11/14/2011 9:04 AM, Nils Kassube wrote:
> Knute Johnson wrote:
>> On 11/14/2011 2:09 AM, Colin Watson wrote:
>>> On Sun, Nov 13, 2011 at 09:40:47PM -0800, Knute Johnson wrote:
>>>> I've got a bash script that I run in cron.daily to backup some
>>>> data to a jump drive. One of the commands in my script is to
>>>> umount the drive. If I write;
>>>>
>>>> if umount /dev/sdb1; then
>>>>
>>>> #do something
>>>>
>>>> fi
>>>>
>>>> it always does it even if the umount is successful.
>>>
>>> The code above means "do something *only* if umount exits
>>> successfully".
>>>
>>> If you want to do something if umount fails, then you need:
>>> if ! umount /dev/sdb1; then
>>>
>>> # do something
>>>
>>> fi
>>
>> Isn't something other than 0 true?
>
> No. The return code 0 means success or true. But there could be several
> reasons for failure, therefore everything else than 0 is failure and the
> number can give a detailed reason for the failure.
>
>
> Nils
>
OK, that explains why I am so confused. Thanks very much, this was
driving me crazy!
--
Knute Johnson
More information about the ubuntu-users
mailing list