Check if Bash Script is ran by Root User

Root users have the privilege to do administrative stuff in Linux and if you’re creating a Bash script to install something or change something in the system, you need root. So, checking whether the script was ran by root is very important. if [ "$EUID" -ne 0 ] then echo "Please run as root" exit fi There is no else condition. You can add the code which will does stuff in root after the above.

[READ MORE]

Replace Strings in Files With PHP & Python

There are softwares already that helps to replace a string in a file. Suppose, if you’re making a program that requires saving some data in to a file. By “adding”, the program is actually replacing a word. Let’s see how it’s done in PHP & Python. This is the file where we are going to replace the word : thisWord I got thisWord for making it thatWord replace thisWord already my friend.

[READ MORE]

Word Palindrome Check in PHP & Python

Palindromes are unique words that are read the same forward and backward. We can identify them using out eyes and brain. How about we identify using a simple program in PHP & Python ? PHP <?php $word = strtolower("Malayalam"); $splitted = str_split($word); $reversedWord = ""; $length = strlen($word); for($i = 0; $i < $length; $i++) $reversedWord .= $splitted[$length - $i - 1]; echo $word == $reversedWord ? "It's a palindrome !

[READ MORE]

Executing Terminal Commands in Python & PHP

Python & PHP are great languages and there are many similarities between them. In this short post, you will learn how to execute terminal commands in PHP & Python. PHP As I said before many times in other posts, there areexec andsystem command to execute commands : exec(“firefox ‘http://subinsb.com’”); Or in the other way : system(“firefox ‘http://subinsb.com’”); Python In Python, there is no exec or system function. But there is a system function in the os nodule.

[READ MORE]

Infinite loop in PHP & Python

Infinite loops are loops that doesn’t have a defined ending. It will continue to run until the program it’s running in is terminated. Normally an infinite loop is created using while loop and is used for continuity of the same program. In this short tutorial, you will learn how to make an infinite loop in both PHP & Python. PHP There is no need of defining any variables. while(1){ print "

[READ MORE]