LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 05-10-2006, 04:36 AM   #1
ashley_31
Member
 
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42

Rep: Reputation: 15
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.
 
Old 05-10-2006, 04:45 AM   #2
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 533

Rep: Reputation: 79
Hi ashley_31

To do do you have to create alise.
 
Old 05-10-2006, 04:56 AM   #3
ashley_31
Member
 
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42

Original Poster
Rep: Reputation: 15
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??
 
Old 05-10-2006, 05:09 AM   #4
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 533

Rep: Reputation: 79
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.

Last edited by angel115; 05-10-2006 at 05:14 AM.
 
Old 05-10-2006, 05:45 AM   #5
ashley_31
Member
 
Registered: May 2006
Location: India
Distribution: RedHat Enterprise Linux (Kernel 2.6)
Posts: 42

Original Poster
Rep: Reputation: 15
Is it better to use this alias command or should i make a shell program for this.??
 
Old 05-10-2006, 06:42 AM   #6
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
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.
 
Old 05-10-2006, 06:58 AM   #7
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 533

Rep: Reputation: 79
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.

Last edited by angel115; 05-10-2006 at 07:00 AM.
 
Old 05-10-2006, 05:29 PM   #8
slackmagic
Member
 
Registered: Aug 2003
Distribution: Slackware
Posts: 253

Rep: Reputation: 32
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!
 
Old 05-10-2006, 06:56 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help with shell script commands Andrew0 Linux - Newbie 1 04-15-2006 12:55 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
commands in shell? kalleanka Linux - General 9 02-01-2006 07:38 AM
Shell commands in HTML? Spooky Programming 8 01-01-2004 11:18 AM
shell commands! krishlinux General 1 10-05-2003 04:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration