Hello, I am new to Linux and need some help with bash shell.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Hello, I am new to Linux and need some help with bash shell.
I am trying to wirte a program that takes three arguments, all representing file names. The script must verify that all names have been provided and if they are not, it should display an error message. If all 3 file names were given, the script should copy the contents of the first two files into the third. If the 3rd file contains data it should be overwritten. This is what I have so far and I can't seem to get it to work correctly.
When posting problems, show the exact output or error messages, and include how you ran the command. Others here don't really want to guess what went wrong. I see one possible problem.
Also, include your code in code tags [ code ] and [ / code ] (without spaces) to maintain the format of your code.
First, the test command (aka '[') needs to have a space on both sides of it:
Code:
if [ $# -eq 3 ]
Secondly, you store data in the variables the right way, but you need to reference the variable with a '$' in front of it when you need to access what is in it:
I don't see why, other than if the file is read-only. Redirection will overwrite everything the file contains which is what the OP wanted.
This is precisely why actual testing on the given environment is necessary, and why I asked the OP to produce the error experienced in the OPs environment:
Code:
$ touch c
$ echo hello > a
$ echo world > b
$ cat a b > c
-bash: c: cannot overwrite existing file
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.