Click to See Complete Forum and Search --> : Checking for existing files with bash script


singlespeed
08-13-2003, 01:07 PM
In a script I'm writing I need to check to see if a file exists and if so, then append some text to it, if not create a file with name blah...

How can I do this in a bash script?

thanks!

EscapeCharacter
08-13-2003, 01:11 PM
if in a test -a returns true

singlespeed
08-13-2003, 02:03 PM
come again??

"if in a test -a returns true"

I'm sorry but I'm not sure exactly what you mean...

I'm looking for the commands I need to use to check if a file exists.

kshim5
08-13-2003, 02:29 PM
if [ -f /etc/foo ]; then


excellent thread on the subject
http://www.justlinux.com/nhf/Programming/Introduction_to_bash_Shell_Scripting.html

singlespeed
08-13-2003, 03:39 PM
Perfect! Thanks!!:D

bwkaz
08-13-2003, 06:56 PM
Originally posted by singlespeed
In a script I'm writing I need to check to see if a file exists and if so, then append some text to it, if not create a file with name blah... Better yet -- let bash do the test for you:

command >>file.txt If file.txt doesn't exist, it'll get created and the output of "command" will get put in it. If it does exist, the output of "command" will be appended to it.