ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm new to Linux (i have latest Ubuntu version), i need to write 2 bash scripts for my OS subject in university, but because I'm new to this, i don't know "how to" well.
I need 2 scripts for Library, one, which name is "jauns" cad add an entry to the Library file, another, which name "mekle" is a search script, that should be able to search the library in 2 ways - 1) by name, 2)by number of book pages.
The Library file has 5 columns - Book name, Author, Publisher, Year of publishing, Book pages (in my script they are Nosaukums Autors Izdevnieciba Gads Lappuses correspondingly(its in Latvian)).
Here is the 1 script's code - jauns:
if [ "$#" != "5" ]
echo Nepareizs argumentu skaits.
echo Lai izveidotu ierakstu, ievadiet argumentus sekojosa seciba:
echo Nosaukums Autors Izdevnieciba Gads Lappuses
echo Piemeeram - Kapitanskaja Doch Pushkin Strela 1886 356
echo -e "$1\t$2\t$3\t$4\t$5" >>bibliteka
echo Pievienots ieraksts:
echo -e "$1\t$2\t$3\t$4\t$5\t$6\t$7"
This one seems to work, but it has some minor things i don't understand.
Why if i enter 5 words with space between them, it does nothing, if I enter 4 or 6-7 it puts the entry in the Library file?
The main problem is the 2 script, here it is- mekle:
if [ "$1" = "1" ]
echo Meklesana pec nosaukuma:
grep "^$2" biblioteka
if [ "$1" = "2" ]
echo Meklesana pec lappusem:
grep "^.* .* .* .* $2" biblioteka
echo Jusu ievade ir nederiga.
echo Pirmais arguments norada pec ka ir jamekle:
echo 1=meklet pec nosaukuma
echo 2=meklet pec lappusem
echo Otrais arguments ir meklejama vertiba
echo Piemeram: mekle 1 Tutepatas
When I run it from Terminal (/path/mekle) it gives me
./mekle: line 19: syntax error: unexpected end of file
What should i do, what did i do wrong? Please help me, I will have my exam on Friday.
I copied and pasted your first script and tested it myself. It worked. I tried 5 inputs and they were entered into the file separated with tabs. With 4, the lines you gave were echoed to the screen. I don't understand what your problem is with it.
The very strange thing that just happened, I still don't know why, though... I've just recopied(last time a did copy/paste from my mekle file to this thread) the source code from my previous thread. Edited the mekle file with Kate editor, the text code ended up there the same as it was, but with a empty line between each line that contains text. And it worked.
Anybody knows why?
Thanks all of you, you made me copy paste it again, and it worked, because of that.
You probably edited your scripts on a Windows machine and then ran them on a Linux machine. Bash probably saw 0x0Ds in your file and crapped out. When you pasted them here, the 0x0Ds were converted to 0x0As. When you copied your scripts from here and pasted them back, bash saw no 0x0Ds and was able to run your scripts.
The moral of this story is to use a real editor if you are going to create scripts on a Windows machine. Notepad or whatever you are using is brain damaged.