Linux Lite Forums

Development => Scripting and Bash => Topic started by: bitsnpcs on September 16, 2018, 09:53:21 PM

Title: Linux Shell Scripting Cookbook
Post by: bitsnpcs on September 16, 2018, 09:53:21 PM
I heard about this book kindly from @Moltke

Thread for everyone to discuss bash learning from this book.

Title: Re: Linux Shell Scripting Cookbook
Post by: bitsnpcs on September 16, 2018, 10:00:24 PM
#2 on the same page

I used a lot of time and tried all kind of things for the increment exercise. Including all from Stack Exchange and AskUbuntu on questions about increments, not specifically this book or exercise.

Code: [Select]
let no1++
Eventually I tried changing the final line to

Code: [Select]
echo $no1
Rather than as I was using which was

Code: [Select]
echo $result
From earlier in #2 section.
Felt a bit silly but was glad I got there in the end.

Hope it saves someone some time in making the same mistake as I had.
Title: Re: Linux Shell Scripting Cookbook
Post by: Moltke on September 16, 2018, 10:31:55 PM

Quote
I found 1 error to date,  page 37 of 384, #3 on the page.

@bitsnpcs I can't find that example on page 37. Are you sure it's the correct page? What's the lesson title/about?
Title: Re: Linux Shell Scripting Cookbook
Post by: bitsnpcs on September 16, 2018, 10:38:52 PM

Quote
I found 1 error to date,  page 37 of 384, #3 on the page.

@bitsnpcs I can't find that example on page 37. Are you sure it's the correct page? What's the lesson title/about?

Page number on the actual book says Page 20 (of the chapter 1), page number for the entire book in the pdf reader says page 37 of 384.

It is in the Title "Math with the Shell", under #3

(https://preview.ibb.co/j1ZW2K/Screenshot_2018_09_17_03_39_27.png)
Title: Re: Linux Shell Scripting Cookbook
Post by: Moltke on September 16, 2018, 10:39:13 PM
@bitsnpcs and everyone else interested, here's the book's link https://gutl.jovenclub.cu/wp-content/uploads/2013/10/Linux.Shell_.Scripting.Cookbook.pdf
Title: Re: Linux Shell Scripting Cookbook
Post by: bitsnpcs on September 16, 2018, 10:44:10 PM
@Moltke  Thank You :)
Title: Re: Linux Shell Scripting Cookbook
Post by: bitsnpcs on September 16, 2018, 10:51:40 PM
Is your page the same ?
Lets hope I don't have the special edition.
Title: Re: Linux Shell Scripting Cookbook
Post by: Moltke on September 16, 2018, 11:41:24 PM
Quote
Is your page the same ?


Yes, it is @bitsnpcs  Btw, I tried the example and it gave me an error just like you said, but copying/pasting right from the book into the terminal does work. Check it out

(http://i63.tinypic.com/2h6d1xu.jpg)

I don't know why but it worked, so I guess that rather than being an error in the book there's something we're not doing or we're doing it wrong.

EDIT: I just found out what the problem was: we were using the " ' " symbol rather than " ` " as in the example. I noticed after running it again using the up arrow, since I copied/pasted the whole thing, I thought it should work that way and it did :) so it's no an error from the book. Thank you for this great idea about creating a thread for the books. :)
Title: Re: Linux Shell Scripting Cookbook
Post by: bitsnpcs on September 17, 2018, 07:47:14 AM
This is the result when using the ` instead of the '

(https://preview.ibb.co/gGGjPz/1a.png)

This is the result not using ` or ' as per my playing with it, (the second running of the file in the terminal, the first is from the above version), the result it is how the book says it should look.


(https://preview.ibb.co/dnjUPz/1b.png) (https://ibb.co/kNzJHK)

@Moltke you are correct, Copying/Pasting from the book or typing it in to the command line does produce 81.0.
It just fails when used as a script that is a file and I am still not sure why that is.

I will edit my earlier post about there being an error in the book.

I'll give this book a miss, I'll stick with the books at home for now.
I may try this book again once I have more experience and can follow it better.

I may even need the book @kpanic described to me "And a child can learn it (with the time they use inall those 'social media' sites)."
I can understand that eg; when learning a new language it is often that you use childrens books in the new language for the first books you read.
Title: Re: Linux Shell Scripting Cookbook
Post by: Moltke on September 17, 2018, 03:39:45 PM
@bitsnpcs  in the first image you get an error because there cannot be spaces between "result=`echo" you wrote "result= `echo" and that's why it didn't work. The whole thing should look like this, with no spaces between " =` " in order to work as it is supposed to:
Code: [Select]
$ result=`echo "$no * 1.5" | bc`
Title: Re: Linux Shell Scripting Cookbook
Post by: bitsnpcs on September 17, 2018, 03:48:04 PM
@Moltke Thank You, your instructions have solved it :)