Programming
How to use logical OR and logical AND in a bash script
Aug 29th
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
echo The logical OR condition met
else
echo The logical OR condition not met
fi
The following snippet shows example usage of logical AND operator.
if [ "$a" -eq 24 ] && [ "$b" -eq 47 ]; then
echo The logical AND condition met
else
echo The logical AND condition not met
fi
How to build in silent mode using GNU make
Aug 19th
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
How to define local links in a web page
Aug 18th
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 previously defined anchor.
<a href="#chapter1">Chapter1</a>
Bash brace expansion to expand arguments
Aug 1st
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 green white
[neo@techpulp ~]#
The above example may not be really useful but you can use bash to expand the arguments by adding prefix or suffix to the braces as shown below to generate expanded arguments. Note that there should not be any space between suffix/prefix and the start/end bracket. Otherwise it is considered as a separate list.
[neo@techpulp ~]# echo {red,green,white}ball
redball More > How to run multiple commands at once in bash shell
Jun 24th
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 three commands “make config”, “make” and “make release” one after the other. The only difference is that you don’t need wait for one command to finish to type in the next command.
However if you have a series of dependant commands that require the previous command to succeed to execute the next command, you can change the command as shown below.
[liz@techpulp ~]# make More >
How to merge two files using text mode in Linux
May 10th
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 inspect the differences and change or move the contents from one window to the other.
First of all, the two file which need merging have to be opened with “vimdiff” as shown below.
vimdiff file1.c file2.c
User can type “Ctrl w w” key combination to switch between windows i.e effectively between two files. You can use standard “vim” commands to copy and paste More >
What is the difference between a macro and an inline function in C
May 8th
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 the other hand, the inline functions are handled by the actual compiler “gcc“.
As the preprocessor is less intelligent, it does blind code replacements wherever it finds usage of a macro. A function described in a macro form doesn’t look nice in terms of code readability. Also arguments taken by a macro do not carry their type and often cause compilation More >
How to force a HTML link to open in a new TAB
Mar 4th
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 “_blank” to force the link to open in a new TAB. The following example shows how to do it.
<a href="http://www.popularmatrimony.com" target="_blank">PopularMatrimony</a>
The following example link shows how it works. PopularMatrimony
Creating alias commands in Bash to make life easier
Mar 1st
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 run set of commands is not so comfortable.
You can define your own command using aliases based on existing commands. For example, you want to mimic Microsoft Windows command line in UNIX or Linux, you define an alias for windows command with the equivalent command in UNIX or Linux. Look at the following example in which a “dir” command is defined More >


Recent Comments