Shell Scripting - how to get command successful result
Posted on 2008-10-16
I am trying to execute a touch command (am open to any other commands as well). In the shell script I want to perform something like this:
IF [ touch file1.txt ]
// File didn't exist but it has been created now
// File already exists
Now I know i can do, IF file_exists but I want to touch a file and ensure that very instant when I touched the file was created and it didn't exist before. Hence if I can't do IF file_exists and then touch.
I want to execute a command (any command, please suggest) that will create the file and along with that return a result to a IF statement informing it about the file creation, else if the file existed then it must not be recreated.
I know this is a little convoluted explanation but it would really help if you can answer this, please ask any clarification questions as well.