Category ‘Programming’
- 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 |
How to build in silent mode using GNU make
Use the following command for absolutely silent build make -s Use the following command for absolutely silent build except printing directory before and after processing. make -s -w ... - TECHPULP |
How to define local links in a web page
The local links in a web page are called anchors. To define an anchor in a HTML page, create a dummy “a” link as shown below. <a id="chapter1"></a> Create a link that user can click on to go to the... - TECHPULP |
How to free cached memory and dirty pages in Linux
When an application reads a file, Linux kernel keeps cache of file contents in memory. The Linux keeps the cache even after application closes the file to improve performance for further read operations of same file. This cache is freed... - 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 |
How to merge two files using text mode in Linux
The Linux provides a command “vimdiff” which can open two files using standard “vim” editor but in two separate logical windows. This is a text-mode based tool. This tool highlights the differences between two files so that the user can... - TECHPULP |
What is the difference between a macro and an inline function in C
The fundamental difference between a macro and an inline function is that they are handled in different phases of binary creation. A macro is expanded during pre-processing stage by the “cpp” command. The “cpp” command is the C preprocessor. On... - TECHPULP |
How to force a HTML link to open in a new TAB
Typically it is good to open a link which takes the user out of current website in a new window or a new TAB so that the user doesn’t leave the original site. The link target can be specified as...