This blog was opened by a team who love foss and is open for all those who love to contribute for foss development. All the foss lovers are most welcome to our blog. Take from it.Do not forget to contribute!
Monday, August 29, 2011
Integer and string Comparison in bash
Integer Comparison
There are 2 ways of comparing integers.
let's consider a and b as integer variables.
if [ "$a" -eq "$b" ] -checks weather $a equals to $b
if [ "$a" -ne "$b" ] -checks weather $a not equals to $b
if [ "$a" -gt "$b" ] or if(("$a" > "$b")) -checks weather $a is greater than $b
if [ "$a" -ge "$b" ] or if(("$a" >= "$b")) -checks weather $a is greater than or equal to $b
if [ "$a" -lt "$b" ] or if(("$a" < "$b")) -checks weather $a is less than $b
if [ "$a" -le "$b" ] or if(("$a" <= "$b")) -checks weather $a is less than or equal to $b
String Comparison
let's consider a and b as string variables.
if [ "$a" = "$b" ] -checks weather two strings are equal
if [ "$a" != "$b" ] -checks weather two strings are different
Useful built-in variables in bash
In bash scripting there are extremely useful build-in variables which we must know.
Given below are some of them.
$#-Number of arguments passed to the script.
$?-Exit status of the last command executed.
$!-Pid of the last command executed.
$$-Pid of the script.
Given below are some of them.
$#-Number of arguments passed to the script.
$?-Exit status of the last command executed.
$!-Pid of the last command executed.
$$-Pid of the script.
How to play sound files in bash
Playing sound files in bash is pretty simple.
All you have do is get install mplayer and execute the command.
sudo apt-get install mplayer
mplayer /path/to/sound/file
All you have do is get install mplayer and execute the command.
sudo apt-get install mplayer
mplayer /path/to/sound/file
Tuesday, August 23, 2011
How to add new menu to the applications menu in ubuntu
how to add new menu to the applications menu in ubuntu
most of us know that we can add new menu to applications menu by right clicking main menu bar and selecting edit menus.Then a window appears with existing menus and you can add any number of menus and items into them. This is a super simple approach which everyone can follow without much trouble.
But what if you need to edit menus programmatically.Do you know how to do it???
This is the guide for you if you need something like that.
first you need to identify the file which specifies the applications menu in ubuntu.It is applications.menu file located in /etc/xdg/menus/ directory.
locate it and examine bit carefully the tag structure in there.If you are familiar with HTML code tags you will understand it easily.
Follow these steps:
1.Open up a terminal and type sudo nautilus,give password,it will give you a file browser with root privilages. We need root privilages since we are going to edit applications.menu file.
2.open applications.menu file in your favourite text editor.You will see there are tag blocks for development,education,science etc. So what we should do is create our own code block which generates our custom menu. Example code block is given below.
< menu >
< name > MyMenuName < /name >
< directory> myMenu.directory < /directory>
< include>
< and>
< category> custom < /category>
< /and>
< /include>
< /menu>
3.place the above code block in between two existing code blocks. for example in between education and science.
Here is a brief description of what the above code really means:
< name> MyMenuName < name>
This tag defines the name of the menu which is self explanatory.But remember it is not the menu visible name in case we specify a name in myMenu.directory file.if we don't give a name in myMenu.directory file it is the menu visible name.The .directory file is explained in the next step.
<directory> myMenu.directory></directory>
There is a .directory file for each of the menus. So we should create a .directory file for our menu and it's name should be given here.
<include>
<and><
<category>custom></category>
/and>
</include>
This part is really important to understand since this determines which are the applications categorized under this menu.><category>custom></category> line indicates that all the applications which has category of "custom" are put in to this menu.
4.Next step is to create a .directory file for our menu.
example myMenu.directory file
[Desktop Entry]
Name=My apps
Comment=my Applications
Icon=/path/to/icon
Type=Directory
X-Ubuntu-Gettext-Domain=gnome-menus
Name specifies the visible name for our menu.And under icon give the path to the icon.
5.place this myMenu.directory file under /usr/share/desktop-directories.
now you are almost done.
6.The new menu will not visible straight-away since there are no items to display. So you can one of the things to get visible your new menu.
i.create your own debian package with category custom and get install it. After the installation new menu will appear with the new application under it.
If you need help in creating debian packages see the article "How to create debian packages".
ii.changecustom to office .then you will see your new menu but with all the office type applications under it.
Here office is used just as an example.
most of us know that we can add new menu to applications menu by right clicking main menu bar and selecting edit menus.Then a window appears with existing menus and you can add any number of menus and items into them. This is a super simple approach which everyone can follow without much trouble.
But what if you need to edit menus programmatically.Do you know how to do it???
This is the guide for you if you need something like that.
first you need to identify the file which specifies the applications menu in ubuntu.It is applications.menu file located in /etc/xdg/menus/ directory.
locate it and examine bit carefully the tag structure in there.If you are familiar with HTML code tags you will understand it easily.
Follow these steps:
1.Open up a terminal and type sudo nautilus,give password,it will give you a file browser with root privilages. We need root privilages since we are going to edit applications.menu file.
2.open applications.menu file in your favourite text editor.You will see there are tag blocks for development,education,science etc. So what we should do is create our own code block which generates our custom menu. Example code block is given below.
< menu >
< name > MyMenuName < /name >
< directory> myMenu.directory < /directory>
< include>
< and>
< category> custom < /category>
< /and>
< /include>
< /menu>
3.place the above code block in between two existing code blocks. for example in between education and science.
Here is a brief description of what the above code really means:
< name> MyMenuName < name>
This tag defines the name of the menu which is self explanatory.But remember it is not the menu visible name in case we specify a name in myMenu.directory file.if we don't give a name in myMenu.directory file it is the menu visible name.The .directory file is explained in the next step.
<directory> myMenu.directory></directory>
There is a .directory file for each of the menus. So we should create a .directory file for our menu and it's name should be given here.
<include>
<and><
<category>custom></category>
/and>
</include>
This part is really important to understand since this determines which are the applications categorized under this menu.><category>custom></category> line indicates that all the applications which has category of "custom" are put in to this menu.
4.Next step is to create a .directory file for our menu.
example myMenu.directory file
[Desktop Entry]
Name=My apps
Comment=my Applications
Icon=/path/to/icon
Type=Directory
X-Ubuntu-Gettext-Domain=gnome-menus
Name specifies the visible name for our menu.And under icon give the path to the icon.
5.place this myMenu.directory file under /usr/share/desktop-directories.
now you are almost done.
6.The new menu will not visible straight-away since there are no items to display. So you can one of the things to get visible your new menu.
i.create your own debian package with category custom and get install it. After the installation new menu will appear with the new application under it.
If you need help in creating debian packages see the article "How to create debian packages".
ii.change
Here office is used just as an example.
Tuesday, August 9, 2011
how to make a text file from terminel easily
how to make a text file from terminal easily
you have to do just only two small steps
step 1
open the terminal and go to location which you want to create a text file
step2
Type the command as below
cat > file.txt
now enter anything which should include inside of the file.txt
now press ctrl+d to save that file.
ok you are done.
cheers.......kwak
you have to do just only two small steps
step 1
open the terminal and go to location which you want to create a text file
step2
Type the command as below
cat > file.txt
now enter anything which should include inside of the file.txt
now press ctrl+d to save that file.
ok you are done.
cheers.......kwak
Subscribe to:
Comments (Atom)