LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   defining our own shell commands (https://www.linuxquestions.org/questions/linux-newbie-8/defining-our-own-shell-commands-443375/)

ashley_31 05-10-2006 04:36 AM

defining our own shell commands
 
hello friends..
i am working on red hat linux (kernal 2.6). Although it has a GUI to work upon but still i wish to work on its shell and be perfect in that too.
Can anybody tell how to create our own shell commands.
i mean that supposedly if some one has to access the cdrom and he does not remember all those shell commands to mount the cd-rom and all that, then i define a command in such a way that it contains all those things required to access the cdrom and the other person just writes the command and he can access the cdrom well..
Hope you people are able to understand my problem..
Please help me out if possible.

angel115 05-10-2006 04:45 AM

Hi ashley_31

To do do you have to create alise.

ashley_31 05-10-2006 04:56 AM

if u wanted to help me, u cud have done it in a better way..
i was doing that blabla bacause i didnt have an idea of how to solve my problem.
how do i create this alise??

angel115 05-10-2006 05:09 AM

Hi

Sorry i didn't got time to write more than this on the previous post

so here is an exemple:
Code:

alias hiden="ls -al"
so now if you type hiden it will execute ls -al

You can do the same thing with mount
Code:

alias mountcd="mount -t iso9660 -o ro /dev/cdrom /cdrom"
so now if you type mountcd it will execute mount -t iso9660 -o ro /dev/cdrom /cdrom

Does it helpfull enought?

ask tell me if you need more help.

Regards,
Angel.

ashley_31 05-10-2006 05:45 AM

Is it better to use this alias command or should i make a shell program for this.??

ethics 05-10-2006 06:42 AM

Depends how involved you want it to be, if its just 1 command for a static drive/mount point run by a user or 2 (alias in their profile, or could be in global profile). Then i would go for an alias as above, if you have different drives/ mount points, i'd make a shell script with user inputted variables. You would also be able to set permissions for your script.

angel115 05-10-2006 06:58 AM

For bash script:

here it is if you want to create a script:
1. Create a text file named "mountcd"
2. Edit it with a text editor and put the following inside:
Code:

#!/bin/bash
mount -t iso9660 -o ro /dev/cdrom /cdrom

3. Change the permission as follow: (this will change the permission to read and execute for all user on this computer) type: man chmod for more info.
Code:

$chmod 555 /Path_of_your_script/your_script
4. login as root and move your script to /usr/bin
Code:

$su
$mv /Path_of_your_script/your_script /usr/bin
$exit


enjoy your new command.

For the alias:
1. edit the file .bashrc in your home folder and add your alias line at the end.
2. Save the change, logout and log back in
enjoy your new command.

slackmagic 05-10-2006 05:29 PM

Quote:

Originally Posted by angel115
For the alias:
1. edit the file .bashrc in your home folder and add your alias line at the end.
2. Save the change, logout and log back in
enjoy your new command.

Or you do your changes to your $HOME/.bashrc, save the changes and then run

Code:

source ~/.bashrc
that way you don't have to log out and log back into your shell again :P


Either way alias or shell script suggested by angel115 will both work just fine ashley_31. Try out both methods and see which one you like best. Good luck!

Tinkster 05-10-2006 06:56 PM

Please do not post threads on the same topic more than once. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php


http://www.linuxquestions.org/questi...d.php?t=443372


All times are GMT -5. The time now is 08:40 AM.