ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In the original script "if" was commented out, but the corresponding "then" was not. That's why bash said "unexpected token 'then'"... Why did you spend so much time correcting a commented out line?
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
Now it works.
Thanks for all the help.
if [ "$#" -ne 2 ]
Here ne means 'not equals'. What is the reason for giving the value 2 here?
Can't we write 3, 4, 15 some other higher value?
I replaced 2 with 32. The program didn't work. I mean copying of one file to another file did not take place. However, there was not any error message; why is that?
$# presumably gives the number of arguments to the script. So, it makes sense to test that $# is not equal to two, because your script requires two arguments: the source and destination files. If you've supplied fewer or more arguments, that doesn't make sense for copying.
No, I didn't find any relevant information in the man pages of 'bash' and 'cp'.
How long did you try for? 1 second, 3 seconds?
man bash
/-e
n
(n x 5 on my machine, took me 4 seconds to get there)
gives you EXACTLY the answer to the -e question of yours.
I think you're just a lazy person who expects others to
regurgitate knowledge and spoon-feed it to you.
I have a splendid idea: why don't you re-write all the
man-pages you don't like reading in a nice way that fits
your taste, and start giving back to the community that
has been pampering you for years in that way?
YOu can get a quicker idea of wht the -e and other such oprions mean by reading the ma page for 'test'. These:
Code:
[ -e file ]
[ -x file ]
[ -r file ]
and other such constructs are constructs of the test program. The '[' means 'test'. However, these are are handled internally by the bash builtins so there are a few differences(bash can handle double brackets, etc). But, still, for the basic usage and tests you may find it much easier to read the 'test' man page rather than the bash man page, which is very long.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
Gnashley
Yes, the command 'man test' gave me the following:
-e FILE [ This means FILE exists]
-f FILE [This means FILE exists and is a regular file]
-x FILE [ This means FILE exists and execute (or search) permission is
granted]
I have file called 'w3' on my system. It is a text file.
I tested the command 'test'. I didn't write a shell script program.
Ni@linux-3vxw:~> test [ -e w3 ]
bash: test: too many arguments
Ni@linux-3vxw:~> test [ w3 ]
bash: test: w3: binary operator expected
Ni@linux-3vxw:~>
Why did I get a strange output?
----------------------------------------------------------
I can't understand what Tinkster has written.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.