Quote:
if test -e w3; then echo "It's a file"; else echo "No such file"; fi if [ -e w3 ]; then echo "It's a file"; else echo "No such file"; fi |
Thanks gnashley.
I wish I knew these things like you. If you know everything, you know how to play with programming as well as shell scripting. The problem is that I don't work with these things at my work. I try to learn these things when I find time. Nowadays I have some free time until 7th of January. I will try to learn shell scripting, sed, awk , grep, egrep, etc. I will do some modifications to the program I made with your help and ask your help when necessary. The usual 'cp' command does not care whether it overwrite the destination file. The program I made with your help is clever. It asks your permission to overwrite. I just came home from the gym. I train 3 times a week at the gym. I will try to modify it later on. By the way, what is the difference between 'exit 1' and ' exit 0 '? Sometimes you write 'exit 1 ' and sometimes it is ' exit 0 '. |
Thanks Uncle_Theodore.
I tried what you have suggested; it works. |
Quote:
|
Quote:
echo $? |
Thanks for the reply.
-------------------------------- if [ "$#" -ne 2 ] ; then echo "Usage: mycp from to" exit 1 ----------------------------------- I just removed the 'exit 1 ' line and reran the program. It worked fine. Of course I gave the name 'mycp8' and ran the command 'chmod 755 mycp8 ' make it an executable one. I expected an error message. No error messages. This means 'exit 1' line is not necessary. |
The $# variable holds the number of arguments given to the script. The original intent of this piece of code
Code:
if [ "$#" -ne 2 ] ; echo $? right after the script exited in the abovementioned case, it will return 1, not 0. |
You are right Nylex.
The regular 'cp' command is different. The program I made has the name 'mycp'. I must always write ' ./mycp file1 file2 '. Is it possible to escape write ' ./mycp ... '? I would like to write ' mycp file1 fil2 ' similar to the ' cp ' command. |
Quote:
I think you'd be much better off just reading this document. http://tldp.org/LDP/abs/html/ Good Luck. |
Quote:
export PATH=$PATH:~/scripts Put all your scripts in there. |
Or, easiest of all, you can place a copy of the script in your regular path -/usr/local/bin would be the best place.
|
I thank Uncle_Theodore, Dive, Gnashley and the others for the comments.
Dive asked whether I am going to write more shell scripts. Everything hinges on time. If I have time, I will do mo work. Code:
The following is my path: |
You need a colon between '.' and '/usr/local/bin'.
|
All times are GMT -5. The time now is 06:44 PM. |