Results 1 to 3 of 3
hi guys,
recently i've been building an automated backup script for our medical systems that run a version of linux on them.
i've had some success but cannot get "if" ...
- 03-09-2009 #1
problems with "if"
hi guys,
recently i've been building an automated backup script for our medical systems that run a version of linux on them.
i've had some success but cannot get "if" commands to work at all.
whereever they pop up, i get:or something similar as an error message. commented out the script runs fine, but loses a nice touch of "detecting" which programs are installed.Code:"if" syntax command
can anyone give me any advice?
i've attatched the script as a .txt
thanks in advance!You know, aliens are going to come to earth in 50 years and kill the hell out of us for DDoSing their networks with this SETI crap
registered linux user #388463
- 03-09-2009 #2Just Joined!
- Join Date
- Feb 2009
- Posts
- 45
<Edit time="2009-03-10T08:33:26.790836095+02:00" reason="Correction">
This answer is wrong and doesnʼt solve the problem in question.
</Edit>
Itʼs simply a matter of a forgotten semicolon, because bourne shellʼs proper «if» construct syntax is:
Originally Posted by cayalee
For more information about bashʼs syntax:Code:if [ «CONDITION» ]; then «CODE» fi
Code:$> man bash […] if list; then list; [ elif list; then list; ] ... [ else list; ] fi The if list is executed. If its exit status is zero, the then list is executed. Otherwise, each elif list is executed in turn, and if its exit status is zero, the corresponding then list is executed and the command completes. Otherwise, the else list is executed, if present. The exit status is the exit status of the last com‐ mand executed, or zero if no condition tested true. […]
- 03-09-2009 #3Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
I don't think it's a matter of missing semi-colons when the 'then' is on a separate line. The problem is further down the script, for example:
Code:[ -d /usr/people/cranial ] then echo "found Synergy Cranial. Preparing to back up" cp /usr/people/cranial/cranialData/* /mnt/usbdisk/cranialData echo "done" else echo "synergy cranial not installed, skipping step" endif
Which should be:
Code:if [ -d /usr/people/cranial ] then echo "found Synergy Cranial. Preparing to back up" cp /usr/people/cranial/cranialData/* /mnt/usbdisk/cranialData echo "done" else echo "synergy cranial not installed, skipping step" fi


Reply With Quote