Shell script which will check the target file and folder exists and copy it
Hi All,
I am a beginner in this and trying to write a shell script which will : 1. Ask for a file name and check if its exists. 2. If file exists only then it will ask for the new target folder, after entering target folder name it will check if it exists. 3. If target folder exists it will copy that file in to it. I have written the below code and it's working fine if file and folder exists but not working properly when any of them is not exists. Code:
#!/bin/bash Please let me know if i missed something. Thanks, Ashish |
I did not test your code, but there obvious error:
You put the second if-else-fi construction in a wrong place. Try this: Code:
#!/bin/bash |
Hi Teufel. thanks for the help.
Now i am trying to do : 1. Ask for a file name and check if its exists. 2. If file exists only then it will ask for the new target folder, after entering target folder name it will check if it exists, if doesn't exits it will create one with with the $location value. 3. It will copy that file in to it. I have made below changes in to above script. Its working but i facing minor issue in it: If i am trying to copy existing file in to non existing folder it's working fine and throwing below message Code:
/etc/inittab copied to /OOO. Code:
#!/bin/bash I will really appreciate if you point out needed changes. Thanks, Ashish |
Issue resolved after :
Code:
#!/bin/bash |
Quote:
Code:
mkdir -p "$location" |
I recommend http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS
Also, in your case, Code:
if [ -d "${location}" ] For debugging, try Code:
#!/bin/bash |
All times are GMT -5. The time now is 06:18 AM. |