Welcome to LinuxScrew

A site for Linux lovers worldwide. For newbies, system engineers, administrators, and everybody in between. We cover all things Linux, plus various programming languages, including Python, Javascript, and PHP.

View our featured tutorials and projects in the slider below or scroll down to see all recent articles.

How to Convert a USB Printer to Wireless with a Raspberry Pi
How to Use a Raspberry Pi for Digital Signage
The Worst Things You’ll Probably Google As a Programmer on Linux
How to Build a Raspberry Pi Internet Kiosk
Browsing the Internet on a 1989 Macintosh II with a Web Rendering Proxy
previous arrow
next arrow
Slider

Why You Should Wrap File Paths in Strings in Your Shell Scripts

Why You Should Wrap File Paths

I stumbled across a thread about terrible programming mistakes and found this: https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/commit/a047be85247755cdbe0acce6f1dafc8beb84f2ac Which contains the line: rm -rf /foo-bar-usr /lib/nvidia-current/xorg/xorg Note – I’ve added foo-bar- to the string so that if you try to run it, it won’t do the thing I’m warning about –even having that on my clipboard makes me nervous!. What happens when it’s run? It wipes out the entire /usr/ directory – essentially bricking your computer! All because of a single space. Due to the space after /usr, the rm command interprets it as two separate directories … Read more

Add Days (or Minutes, or Hours) to Javascript Date [or Subtract]

Add Days to Javascript Date

This article will explain how to add (or subtract) days, minutes, hours, seconds (etc.) to a JavaScript date. Why would you want to do this? Perhaps you want to tell a user that their assignment is due in a week and provide the date, or maybe your application needs to know what the date was 30 days ago to pop up a reminder – there are near-infinite usage cases. Add Days to Date Using Vanilla JavaScript First, here’s how it’s done in plain old JavaScript: … Read more

MySQL vs MariaDB vs MongoDB vs PostgreSQL vs SQLite vs MS SQL – Which to Choose?

Which database to Choose

There is a lot of weird-sounding language around databases. Most of it centers on the names of the popular database software which is available. It can make it tough to choose. Each strangely named database solution offers features making it suitable for different tasks. This article should shed some light on what’s what. SQL Is a Language SQL (pronounced ESS-QUE-ELL or sequel depending on which side of the raging debate you side with). It stands for Structured Query Language. It is not a piece of software – it’s the … Read more

6 Best PHP Frameworks to Consider in 2021

Best PHP Frameworks

PHP frameworks speed up the development of complex applications greatly. This article features 6 of the most popular frameworks to consider in 2021. These frameworks provide varying scaffolding levels to get you started, from database operations, object handling, user authentication, and page templating. So you are free to build your application without having to constantly write and re-write the common functions that make your application work. They also come with some security benefits – using a sanitized database abstraction layer that has been written and … Read more

Categories PHP

Command Line Arguments in Shell/Bash Scripts [Tutorial]

Command Line Arguments in Bash Scripts

This tutorial explains how to pass command-line arguments to your bash scripts. There are many examples included to help get you started. Bash/Shell scripts are a great way to automate your Linux workflow and speed up your workday so you can leave the office early (or hide in the server room until 5 pm hits). Making scripts re-usable makes them more useful – you don’t need to write a script that does the same task for different sets of information or on different days – … Read more

PHP shell_exec Function: How to Use It [With Examples]

PHP shell exec Function

This tutorial explains how to use the shell_exec function in PHP in order to execute code via the shell and return the output as a string. PHP is a versatile programming language for building server-side web applications, but sometimes you need to execute code from another environment and use the result in PHP. This can be achieved by using the shell_exec function to execute commands on the system’s shell hosting your PHP code and return the result as a string to PHP. When doing so, there are security … Read more

Categories PHP

Javascript eval() Function (and Why to NEVER Use It)

Javascript eval Function

The JavaScript eval() function executes a string as JavaScript. This is a massive security risk as, if used in production, it can allow third parties to execute their own code in your app. eval() Syntax eval(string) Note that: string is a string that contains JavaScript Code eval() will return the value returned by executing the code in the string Just don’t use it Example of Javascript eval() This article gets one example only so you can see how eval() works, so that if you accidentally fall on your keyboard and the … Read more

Python Main Function & Method: What Is It and How Is It Used?

Python Main Function Method

As you build more complex Python apps, you will probably want to start splitting your code into separate files. What Is the __main__ Function? Importing and executing code from another file is common in even small scripts and apps built with Python. As your library of scripts increases, you may choose to import previously written code into new projects. The __main__ function in Python is only executed when the script is called directly, allowing you to set different behavior based on how your code is being … Read more

How to Get User Input in Python [With Examples]

Get User Input in Python

This article covers getting user input on the command line using Python 2 or 3 and includes some useful examples. Get User Input in Python 3 Python 3 uses the input() function to collect user input: myText = input(“Enter some text:”) print(“You entered the text: ” + myText) Get User Input in Python 2 If you’re still using Python 2, you will use the raw_input() function instead: myText = raw_input(“Enter some text:”) print “You entered the text: “, myText # Python 2 uses different syntax to print output Typing Input … Read more

Assign Variables, Global Variables and Scopes in JavaScript (let, var, const)

JavaScript let var const

let, var, and const are all JavaScript statements that assign a value to a variable. Their behavior can differ depending on how and where they are used in your code – read on to find out the details. Scopes in JavaScript As you start to build more complex applications, you’ll start to see a lot of talk about scopes. A variable’s scope defines where it is available in your application. Global Scope (Global Variables) If a variable is in the global scope, it is available anywhere in your application. It can be called … Read more