How Do You Troubleshoot the Bash Script Error “line 5: $’\r’: command not found”?

Problem scenario
You drafted a Bash script on a Windows computer.  You then uploaded it to Google Cloud Platform via a web browser feature.  When you run the bash script on a Linux server (e.g., in GCP), you get this error “line 5: $’\r’: command not found”.  You do not want to install dos2unix or any new packages.  What should you do?

Solution
The file needs to be modified or “cleaned up.” 

What Are Some Tips on a Bash Programmer Becoming a PHP Programmer?

Problem scenario
You are a Bash programmer, but you want to learn how to code in PHP.  How do you learn to develop PHP scripts when you have a Linux bash background?

Solution
If you are new to PHP programming and familiar with Bash programming, remember these tips:

1.  Variable assignments involve the variable with the syntax of a cash sign “$” before the variable name. 

How Do You Instantiate a class in Python?

Problem scenario
You inherited code from a different programmer. You want to test out an object. How do you create an object of a pre-made class?

Solution
Look at how many variables the class has. Take this code for example:

class Cartesian(object):
def __init__(self,a = 0,b = 0):
self.a = a
self.b = b

def distance(self):
return (self.a**2 + self.b**2) ** 0.5 # Pythagorean theorem. …

How Do You Troubleshoot the Oracle and Java Message “java.sql.sqlexception ora-01003 no statement parsed”?

Problem scenario
You run a Java program that runs a SQL statement in an Oracle database.  You get this error: “java.sql.sqlexception ora-01003 no statement parsed”.  What do you do to fix this?

Solution
Run the Java program a second time.  Does the problem remain?  It could be that there was a successful DDL command, and this error could be ignorable.  

You may want to try these links for further info:
https://stackoverflow.com/questions/23866710/ora-01003-no-statement-parsed
https://community.oracle.com/thread/736289 (this link used to work)

How Do You Use Encapsulation in Python?

Problem scenario
You know about encapsulation.  You know about private methods that are only accessible from inside a class — not outside.  You want to encapsulate a method in a class in Python.  How do you write such a program?

Solution
“Programmers are most effective if shielded from, not exposed to, the innards of modules not their own.” (This was taken from page 272 of The Mythical Man-Month.)

Here is an example;

With awk, What Do You Do to Get a Colon To Be Recognized as a Separator of Fields?

Problem scenario
You have Awk 4.1.3 installed.  The default field separator in awk is a space.  You want to assign it to a different character — specifically a colon “:”.  You have a string with a colon assigned to the variable “y”.  You have tried these things:

echo $y | awk -F “:” ‘/1/ {print $NF}’  # this prints nothing
echo $y | awk ‘{FS=”:”;

How Do You Write a Java Program to Accept a Number for the Command Terminal and Print It Back Out?

Problem scenario
You want to write a basic Java program to test it out.  How do you write a program to accept user input, specifically a number, and print it back to the screen (using the integer data type)?

Solution
1.  Install the Java Development Kit if you have not installed it yet.  If you are not sure you have it, run javac -version

How Do You Use a Jenkins Pipeline with a Scripted Syntax?

Updated and re-tested on 9/24/19
Problem scenario
You read about what Jenkinsfiles are.  Coveros.com defines them as ‘Jenkinsfiles, using a domain specific language based on the Groovy programming language, are persistent files that model delivery pipelines “as code”, containing the complete set of encoded steps (steps, nodes, and stages) necessary to define the entire application life-cycle.’

You want to use a Scripted Pipeline in Jenkins (via a Jenkinsfile).