Check Syntax of a Bash Script Without Running It in Linux

Satish Kumar
Updated on 23-Dec-2022 11:17:11

1K+ Views

Overview Here, we’ll see how we can validate the syntactical correctness of a bash script without actually executing it. We’re going to examine some of the Bash and external tools that can be used for that task. Configure Let’s first write a simple script that we’ll be using in almost every example throughout the tutorial. $ cat unity_check.sh #! /bin/bash read -p "Enter the input: " num1 if [ -z "$num1" ] then echo "The number is empty" exit 0 fi if [ "${num1}" -eq 1 ] then echo "Number entered is 1" else echo "Not equal to One !!" ... Read More

Find Last Directory or File from a Given Path

Satish Kumar
Updated on 23-Dec-2022 11:14:58

727 Views

Overview We often use shell scripts or work with Linux commands when handling paths. Extracting the last part of a given file name is a fairly common task. For example, if we're trying to access /tmp/dir/target, then we want to be able to access target as a file name. Yes, this looks easy enough. But there might be some edge cases that could cause us to fail. We’ll take a close look at this problem and explore some common solutions. Discussion of Common Solutions We know that Linux file systems don't allow slashes (/) to be parts of filenames or ... Read More

Huffman Coding Algorithm

karthikeya Boyini
Updated on 23-Dec-2022 11:05:46

34K+ Views

Huffman coding is a lossless data compression algorithm. In this algorithm, a variable-length code is assigned to input different characters. The code length is related to how frequently characters are used. Most frequent characters have the smallest codes and longer codes for least frequent characters.There are mainly two parts. First one to create a Huffman tree, and another one to traverse the tree to find codes.For an example, consider some strings “YYYZXXYYX”, the frequency of character Y is larger than X and the character Z has the least frequency. So the length of the code for Y is smaller than ... Read More

Copy SSH Keys to Different Linux Machine

Satish Kumar
Updated on 23-Dec-2022 11:03:39

623 Views

Overview When working with SSH keys, it is important to keep them safe. We can protect ourselves against accidental deletion by storing them in an encrypted file. We can also make sure they aren’t compromised if someone tries to steal them by keeping them offline. For example, we could store them in a password protected folder on a USB drive. However, this isn’t the best way to do things. If you have multiple machines and want to copy your key from one machine to another, then there are better ways of doing that than copying the key files over. This ... Read More

Most Common Flags Used in /proc/cpuinfo

Satish Kumar
Updated on 23-Dec-2022 10:38:52

1K+ Views

Overview We’ll go through some of the features available on the CPU installed on our computer’s motherboard. We’ll briefly look at the concept of virtual file systems before we dive into the details of the topic. Afterward, we’ll discuss the flags obtained from the /proc/cpuinfo virtual directory for different CPU manufacturers such Intel, AMD, and Arm. Virtual Files A virtual file system (VFS) is an abstraction layer that allows us to treat files as if they were stored on a disk drive. The VFS provides a way to access data without having to know where it actually resides. For example, ... Read More

Get Denominator from a Rational Number in Golang

Akhil Sharma
Updated on 23-Dec-2022 10:26:31

291 Views

In this article, we will discuss how to get the denominator from a rational number. Rational numbers − In mathematics, rational numbers are defined as numbers that can be expressed in the form of a/b where a and b are integer values. For example- 1/3, 5/8 etc. Note that the denominator of a rational number can never be zero. Syntax func NewRat(a, b int64) *Rat func (x *Rat) Denom() *Int NewRat() function takes two integer numbers as input arguments and returns a rational number in the form of a/b. here a is the numerator and b is the denominator ... Read More

Get the Numerator from a Rational Number in Go

Akhil Sharma
Updated on 22-Dec-2022 18:31:40

317 Views

In this article, we will discuss how to get a numerator from a rational number. Syntax func NewRat(a, b int64) *Rat func (x *Rat) Num() *Int NewRat() function takes two integer numbers as input arguments and returns a rational number in the form of a/b. here a is the numerator and b is the denominator of a rational number. Num() function in the Go language returns the numerator of a rational number as the result in integer format. Method-1 Go language program to get the numerator from a rational number. Algorithm Step 1 − Import the fmt and ... Read More

Convert Character to String in Go

Akhil Sharma
Updated on 22-Dec-2022 18:30:24

4K+ Views

In this article, we are going to learn about how to convert characters to string go programming language. Chars − Go language does not have a char data type on the contrary characters in go language are represented by rune data type. Rune represents a character value that is encoded in UTF-8 format. The size of the runes is 32-bits. Strings − String data type is used to store a sequence of characters. it can be in the form of literals or alphabets. The size of the string variable is 1 byte or 8 bits. There are two approaches to ... Read More

Golang Program to Create an Interface

Akhil Sharma
Updated on 22-Dec-2022 18:24:13

1K+ Views

In this article, we are going to learn about how to create an interface using golang programming INTERFACE − In the go language, an interface is a custom type that is used to specify one or more method signatures. An interface is abstract i.e. we cannot create an instance of the interface but we can create a variable to the interface type and assign this variable to the struct or class that has methods needed by the interface. Syntax type interface_name interface { // method signatures } Example 1 To define an interface first we need ... Read More

Golang Program to Create Abstract Class

Akhil Sharma
Updated on 22-Dec-2022 18:21:48

3K+ Views

In this article, we are going to learn about how to create an Abstract class using Golang Programming Abstract Class − A restricted class is called an abstract class which cannot be used to create an object from it to access an abstract class, it must be inherited from another class. The Go interface lacks fields and forbids the definition of methods inside of it. Any type must implement every interface method in order to belong to that interface type. There are situations in which having a method's default implementation and default fields in GO is helpful. Let's first grasp ... Read More

Advertisements