Skip to main content

Posts

Install Linux Inside Windows Using VirtualBox and WSL Ubuntu

There are several ways to install Linux. You can clean everything from your system and install Linux. You can dual boot Linux with Windows and it allows you to choose one of the operating systems at the boot time. You can also install Linux within Windows from Microsoft Store. But this only provides you the command line version of Linux. If you want to use Linux without making any changes in your Windows system, you can go the virtual machine way. Basically, you install and use Linux like any regular Windows application. When you just want to try Linux for limited use, virtual machines provide a more comfortable option. VirtualBox is a free and open source virtualization software from Oracle. It enables you to install other operating systems in virtual machines. It is advised that your systems should have at least 4GB RAM to get a decent performance from the virtual operating system. Requirements Good internet connection to download software and Linux ISO. You can also use s...

Bash on Windows-10

Bash on Windows provides a Windows subsystem and Ubuntu Linux runs on top of it.  It is a complete Linux system inside Windows 10. Basically, it allows you to run the same Bash shell that you find on Linux. This way you can run Linux commands inside Windows without the need of installing a virtual machine or dual booting Linux and Windows. You install Linux inside Windows like a regular application. This is a good option if your main aim is to learn Linux/Unix commands. Step 1: Enable “Windows Subsystem for Linux” feature The first thing you need to do is to enable Windows Subsyetm for Linux feature from PowerShell. Go to Start menu and search for PowerShell. Run it as administrator: Once you have the PowerShell running, use the command below to enable Bash in Windows 10. Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux You’ll be asked to confirm your choice. Use Y or press enter: Step 2: Download a Linux system from Windows store ...

String Hadling in Bash Shell

Strings can be handled efficiently using string functions in bash shell. The following are the commonly used functions Finding length of the string length: will return the length of the string Eg: str=”This is a test string” len=`expr length “$str”` echo $len o/p:21 In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable with its value. This feature of shell is called parameter expansion.   Parameter expansion has numerous other forms which allow you to expand a parameter and modify the value or substitute other values in the expansion process. We can use the parameter expansion concept for string manipulation operations.   Syntax:${#string} Eg: str="This is a test string" len=${#str} echo $len Extracting a substring substr Eg: this will extract 3 characters from 2 pos ie; his str="This is a test string" sstr=`expr substr "$str" 2 3` echo $sstr In the parameter expansion position starts from 0....

Functions in Bash shell

Functions in Bash Scripting are a great way to reuse code. In this section you'll learn how they work and what you can do with them. Think of a function as a small script within a script. It's a small chunk of code which you may call multiple times within your script. They are particularly useful if you have certain tasks which need to be performed several times. Instead of writing out the same code over and over you may write it once in a function then call that function every time. Creating a function is fairly easy. They may be written in two different formats: function_name () { #code to execute } or function function_name { #code to execute } The function can be called with just function_name Example1: f() { echo “This is a test function...f” } f Example2: function f { echo “This is a test function...f” } f function_name : The name of the function. Curly braces {} : Enclose the code block. Functions are declared before being called.   Passing Arguments I...

Flow Control in shell script - if and case statements

Shell script usually consist of sequence of commands that starts at the first line and continues line by line until it reaches the end. Most programs do much more than this. They make decisions and perform different actions depending on conditions. The shell provides several commands that we can use to control the flow of execution in our program. In this lesson, we will look at the following:  test if case exit   test The test command is used most often with the if command to perform true/false decisions. The command is unusual in that it has two different syntactic forms: # First form test expression # Second form [ expression ] The test command works simply. If the given expression is true, test exits with a status of zero; otherwise it exits with a status of 1. Common numerical test conditions -gt   Greater than -lt    Less than -ge  Greater than or equal to -le    Less than or equal to -eq   Equal to -ne...

Writing a Bash Shell Script

Bash shell scripts in Linux are text files that contain a series of commands that can be executed by the Bash shell. Bash (Bourne Again Shell) is a popular shell in Linux and UNIX systems, and shell scripts are used to automate tasks, configure systems, or perform a sequence of operations. How to Write a Bash Shell Script Create a New File: You can create a new script using any text editor like nano , vim , or gedit . gedit myscript.sh Write the Script: A basic shell script begins with a "shebang" ( #!/bin/bash ) to specify the interpreter that will be used to execute the script. The rest of the file contains the commands to be run. Example of a simple script: #!/bin/bash # This is a comment echo "Hello, World!" # Print "Hello, World!" #!/bin/bash : Specifies that the script will be executed using the Bash shell. echo "Hello, World!" : A command that prints the string "Hello, World!" to the terminal. Comments: Any line starting ...

I/O Redirection

In this we will explore a powerful feature used by many command line programs called input/output redirection . As we have seen, many commands such as ls print their output on the display. This does not have to be the case, however. By using some special notations we can redirect the output of many commands to files, devices, and even to the input of other commands. Standard Output Most command line programs that display their results do so by sending their results to a facility called standard output . By default, standard output directs its contents to the display. To redirect standard output to a file, the ">" character is used like this: $ ls > file_list.txt In this example, the ls command is executed and the results are written in a file named file_list.txt. Since the output of ls was redirected to the file, no results appear on the display. Each time the command above is repeated, file_list.txt is overwritten from the beginning with the output ...