What does (#)/[some_folder] mean at the beginning of that Shell script example? - bash

I have no serious tech background, just know some Python basics. Became interested in Flask, read the Flask tutorial, saw that Flask requires setting some environment variables. Didn't know what that is, this led me to Linux and now I'm sort of addicted to that Linux Bible, I have the 9th edition. Normally man pages + Google always have answers for me. Not this time.
So there's an example backup script on p. 168, the second line right after the shebang line is:
# (#)/my_backup
The /my_backup part does not show up anywhere in the example script again and I get that this is commented out but it bugs me that the (#) part looks like being meaningful and I can't find any information on this. Searching the bash man pages only has unrelated results and Google wasn't helpful either.
Can anyone explain to me why this line is in the example script? I understand all of the script except the reason why the 2nd line looks how it looks. Have I overlooked something important while reading the book?

Related

I may sound very dump lol - but getting everything straight in the first place is better than not to ask at all

Beginner with python - I am taking a class with data camp and in one exercise, I used " # " to add my comment, after running the code, the comment is not showing up I believe it should right.
Did I miss anything or is the exercise screen has a bug or something? This question is too simple, I may sound dump but rather focus on learning the basics before moving on. lol.
If your line starts with the comment sign #, then the python interpreter will ignore this line.
So if you run these lines:
print("Hello earth")
# print("Hello moon")
The output will be only Hello earth

How to get started posting a question with Stack Overflow?

I know this is going to sound extremely stupid but I honestly cannot figure out how to post a question I have here for a program I am trying to make.
Whenever I paste my code into the code section this website tells me I have not formatted correctly. I triple check everything and it is all perfectly formatted. It is strange though because my code ends up being halfway into the place where I am suppose to describe the issue. So I am definitely doing this wrong.
Would somebody please walk me through a simple tutorial so I can finally ask my questions?
Honor to help you, I think you can first learn how to use markdown.
And this is two useful tutorial I read when I am learning.
Perfect question : WRITING THE PERFECT QUESTION
Use Markdown effectively : Markdown Getting Started
As for the display of code you mention above, you can use triple ``` to surround the code like this
import math
print('hello world')

How to reference and run a python document from the python interpreter

I just want to be able to run a python script from the interpreter, so that I can work on my changes to my script in notepad or other editor, save, and then interactively test changed code in the python interpreter.
Also, IDLE is not a solution. I'm operating on a government computer that is blocking the port it uses to communicate interaction between console and module.
To clear up any confusion, here's a demonstration of what I'm trying to do:
So, how do I do it?
EDIT:
Okay so I found a statement that does what I want. exec(open('dir').read()). The problem I think is that the directory I want to refer to contains periods. But I'm sure this will work, because open('dir').read() produces a string of the contents of a document specified, as long as I reference the likes of C:\myTest.py, and exec() obviously runs strings as input. So how can I reference files from the location I want?
Okay so the problem seems to be that Windows addresses often contain what python sees as 'unicode exits'. I'm not sure what they do or how they work, but I know they start with \ and are followed by a single letter and that there are enough of them to use up half the alphabet. There are a few solutions but only one is worth a damn for this application. I came across an operator that can be used in conjunction with strings, similarly to how + can be used to concatenate multiple strings, it seems r or R if you prefer (interestingly), can be used immediately before a string to tell the interpreter to take the string 'literally' as a string, and nothing else.
One would think that the quotes would be enough to express this, but they aren't and I'll probably eventually find out why. But for now, here's the answer to my question. I hope someone else finds it useful:
In plain text: >>> exec(open(R'C:\Users\First.Last\Desktop\myScript.py').read())

Filter out HTML code with grep

I am working on a project using a bash shell script. The idea is to grep a wget retrieved page, in order to pick up a certain paragraph on the web page. The area I would like to copy, usually starts with a
<p><b>
but the paragraph also contains other bits of HTML code, such as anchor tags, that I don't want to be in the output of the grep.
I have tried
cat page.html| grep "<p><b>" >grep.txt
and then I grep the output file, which now contains the paragraph I want
cat grep.txt|grep -v '<p>|<b>|<a>' >grep.txt
but then all it does is clear everything from the file and not read anything. How can I get it to exclude only the HTML code?
I am also trying to follow the links that are in the paragraph that I grep, in order to do the same thing with those pages. Only 2 levels deep, so the main page and then what ever sub page(s) stem from the first paragraph of the main page. I know this is a difficult idea, hopefully I explained well enough to get some help. If you have any ideas, any help is appreciated.
Do you have to do this in bash? It seems to me that Python would lend itself to this problem, in particular a library called Beautiful Soup.
I've used this for parsing HTML in the past and it's the easiest tool I could find. It has good documentation for dealing with html.
Perhaps you could make a standalone python code that extracts the HTML and then echos the string you're after. The python code could then be called from inside your bash script if you have some bash functions you want to perform on the string.
I know this is 7 years old but just posting solution I have with bash
https://api.jquery.com/jquery.grep/

Bash keyboard shortcut to add comment character (#) to beginning of command line

When using Mac OS X including iTerm, I can simply press
Shift+$ and the line in bash that I am currently tiping will get a # added to the beginning and the line returns. I like this very much as it prevents from actually executing that command while still editing it and I don't have to jump to the beginning of the line to insert that # character there.
However, when I log onto our cluster, this functionality is lost. I tried to search for this feature but only found posts about using sed etc. so suggestions which are not for the interactive kind of using bash that I am referring to.
Could somebody please point me to a resource where this functionality is explained (bash-guide?) so I could look up how to make it work when logging in to other machines? Or is this something Mac/iTerm-specific? But then, I would expect it to work also on our cluster, as long as I use my machine of course.
This might work for you
See insert-comment (M-#)

Resources