Problems with simple script....
Please be gentle. I know NOTHING about Bash Scripting. I promise I'll read up on it after someone holds my hand first.... :D
And there is an existing ~/Desktop/test.txt already. Code:
#!/bin/sh |
Hi,
First thing I noticed is the here-document structure that is not correct. Although it looks nice to ident code in an if-then structure, you do need to use the here-document tokens exactly the way it was declared. Code:
if [ -x ~/Desktop/test.txt ]; then Hope this gets you going again. |
Hmm... That sort of makes sense after reading about it... :scratch:
Atleast I'm getting something different. [root@darkstar ~/Desktop] sh test test: line 11: unexpected EOF while looking for matching `'' test: line 14: syntax error: unexpected end of file That should be right. It said the dilemeter is the matching result of word only without the quotes and with no prepending spaces, so... yea. Your right. Still doesn't seem to be working. Well, basically, I'm just lost. It doesn't have to append at the end of the file nor does it have to use an if/then structure. I simpily need to append some text to an existing file (cat is the only way I know how), wherever it goes (beginning/middle/end), and then I need to run another command after that... Man I'm stumped. I'll keep looking for literature but any additional help would ofcourse be welcome. Thanks again! |
Hi again,
There are some more 'syntax errors' in your script: This: echo 'I'll run another command here if I figure out the above' won't work. The ' in I'll is seen as the closing pair for the ' that's behind echo. This is a better solution: echo "I'll run another command here if I figure out the above" You can also 'escape' the special character: echo 'I\\'ll run another command here if I figure out the above' I also expect that the use of -x is incorrect (are you looking for a directory or executable file??). If you want to check if the file already exists you should use the -a Your script should look, something like this: Code:
#!/bin/sh Hope this clears things up a bit more. |
Nice.... Thanks.
So, basically it was the EOF indent on Line 8 and the -x switch that was holding me up. I was stumbling to be sure. I knew my line 14 syntax error was something silly. I've caught myself using apostrophies in echo's more than once... :rolleyes: So, this works as expected then Code:
#!/bin/sh |
Here's a free Bash scripting guide from TLDP (The Linux Doc Proj).
http://www.tldp.org/LDP/abs/html/index.html enjoy + merry xmas :) |
incidentally, it's NOT a bash script.
you have Quote:
|
All times are GMT -5. The time now is 10:00 PM. |