Category ‘Bash’
- TECHPULP |
Count number of characters (strlen) in a bash variable
The following example shows the functionality of strlen in a bash script. [neo@techpulp ~]# echo $HOME /home/neo [neo@techpulp ~]# echo ${#HOME} 9 bash# The following defines an utility function that can be used in a bash script. #!/bin/bash function strlen()... - TECHPULP |
How to use logical OR and logical AND in a bash script
The operators used in bash scripting for logical OR and logical AND are “||” and “&&” respectively. The following snippet shows example usage of logical OR operator. if [ "$a" -eq 30 ] || [ "$b" -eq 40 ]; then... - TECHPULP |
Bash brace expansion to expand arguments
Braces can be used to expand arguments in bash. Bash expands a list of strings separated by commas with in braces to a list of strings separated by spaces. Look at the simple example below: [neo@techpulp ~]# echo {red,green,white} red... - TECHPULP |
How to run multiple commands at once in bash shell
All commands can be just appended using a semicolon (;) to make the bash to run all the commands one after the other as shown below. [liz@techpulp ~]# make config; make; make release The above command is equivalent to running... - TECHPULP |
Creating alias commands in Bash to make life easier
If you have longer command or a set of commands that needs to be run repeatedly and you are tired of typing full command or using history to run them, then alias commands are designed for you. Using history to... - TECHPULP |
Bash script to replace a word or a string in multiple files at once
There are multiple ways of replacing a word or a string with another in a stream of input. Here, in this article, we use “sed” command. While the “sed” command operates on one file at a time, the bash script... - TECHPULP |
Bash script to delete blank lines from a file
There are multiple ways of deleting blank lines from a file. This article tells how to use “grep” command to achieve the objective. The “grep” command provides an option “-v” to invert the matching. That means grep finds the lines... - TECHPULP |
How to take password interactively in a Bash shell script
If you are not familiar with interactive bash programming, please read this article as well. Typically “read” command is used to prompt the user to respond and read the input from standard input. The “read” command, by default, shows whatever... - TECHPULP |
How to set time out to interactive prompt in Bash
If you are not familiar with how to show interactive prompt in Bash shell script, please read this article first. Typically “read” command is used to read the response from the user. By default, the “read” command waits forever for... - TECHPULP |
How to show interactive YES/NO prompt in Bash
The Bash shell provides an in-built command “read” to read a line from the standard input. The following sample script prompts user to provide his answer as either “yes” or “no“. [neo@techpulp ~]# cat yesno.sh #!/bin/bash echo -n "Do you...