An array is a data structure consist multiple elements based on key pair basis. Each array element is accessible via a key index number. This tutorial will help you to create an Array in bash script. Also, initialize an array, add an element, update element and delete an element in the bash script. Define...
Bash scripts are very useful for doing work easier. It also helps for task automation. This tutorial will help you to how to include bash script in other bash script. Create Sample Scripts For example, I am creating two scripts, first is config.sh which contains some variables. Second script is our main script main.sh,...
Question – How to add [Y/n] confirmation in our own shell scripts? Many times you have seen commands ask for confirmation [Y/n] or [Yes/No] input. This is a very useful part to know if a user wants to proceed with remaining steps for not. You can also add the same function to your script....
This is good to test a file has enough permission to do read, write or execute operation’s. For a good programmer you should use these functions before doing any operations on file. 1. Test if File has Read Permission: Below script will check if given file has read permission for current logged in user....
While working with bash shell programming, when you need to read some file content, It is good to test that given file is exits or not after that test if file is empty or not. This will safe your script from throwing errors. This article will help you to test if file exists or...
DOCUMENT ROOT is the path where application is stored on file system. In some application’s we need to use absolute path of any file or script in our php script, While development we really don’t know where application will be hosted on server. In that case we can use php function getenv() to get...
A Command-line Arguments are passed after the name of a program in command-line operating systems like DOS or Linux and are passed into the program from the operating system. Shell scripts also accept command line arguments similar to nix commands. Command line arguments are useful for passing input to script at runtime which has...
Similar to for loop, while loop is also entry restricted loop. It means condition is checked before executing while loop. Mostly it also can do all the works which for loop can do but in uses it has own benefit of use in programming. Syntax: while [ condition ] do // programme to execute...
Loops are very useful for doing repetitive tasks for any programming language. For loops are also available for bash scripting. In this article we will learn about uses of for loops with useful examples. Syntax: for VARIABLE in PARAM1 PARAM2 PARAM3 do // commands to execute done In above syntax PARAM1, PARAM2 and PARAM3...
Command SNAME=$(basename “$(test -L “$0” && readlink “$0” || echo “$0″)”) While running a bash script using Linux terminal the script name can also passed as argument at $0. but if we are using full path of script to execute, it will show full path as results when print value of $0. So use...