Results 1 to 5 of 5
hi guys, been absent from here for a while but need some help with creating a script. i've been trying to build a shell script that tests to see if ...
- 05-26-2009 #1
problems with "if"
hi guys, been absent from here for a while but need some help with creating a script. i've been trying to build a shell script that tests to see if a folder is present and if it is, then copy it to a predefined backup location.
however, it just keeps giving me the following error
so the way i've built it is like this:Code:if: Expression Syntax
as i understand it, using [ ] is the same as using the test command, and the -d option specifies its a directory. i want it to check whether a program is installed, and if so copy some files. if not, tell me that its not installed and move on.Code:if [ -d /usr/people/cranial4 ] then echo "found cranial, preparing to back up" cp /usr/peoplecranial /mnt/usbdisk/cranialdata else echo "cranial not installed, skipping step" fi
where am i going wrong? i'm bouncing my head off the wall
thanks in advance guysYou 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
- 05-26-2009 #2
very strange, I tested script
very similar to yours, works for meCode:#!/bin/bash if [ -d /home/ccooper ] then echo "1" else echo "0" fi
- 05-26-2009 #3
it is very weird, i've been building this on ubuntu/DSL and then trying to run it on the work linux (2.4.1 kernel) and it doesn't like it. i can build a similar script using same commands etc on the work machine and it plays nicely..
no idea what the issue is but need to do a rebuild by the looks..
cheers!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
- 05-27-2009 #4Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
I suspect it's not the problem of the kernel. I think it has something to do with the default shell on your work computer. If I'm not mistaken, it is either:
1. a line #!/bin/csh at the beginning of the script in question,
2. the default shell is csh on the work computer [ use echo $SHELL to find out ]and the shebang line #!/bin/bash is missing.
To replicate the problem, change the shebang line on the scripts listed on this page so far to #!/bin/csh and run the script in this way: (script needs to be made executable first)
I think it's a good habit to specify which shell you will be using in the script otherwise problems like this will surface.Code:./script
Reference: if: Expression Syntax. Blog of Annoying Technical Details
- 05-29-2009 #5
thankyou very much for this, most usefull!
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


Reply With Quote