Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I understand that with the alias command i can do this...
alias d="ls"
Then type d, and it will execute that command. But can i use alias to set options for programs. Like if everytime im gonna use ls, im gonna use the -a option i can do this...
alias ls="ls -a"
But what if i want to add the -l option one time. What im trying to say is, is there a way to have a default set for a command, but also be able to change it on the command line? Let me know if i didnt explain that right.
I wouldn't recommend using alias to change a command name, at least not the way you suggest. I'd recommend creating a simple script that runs the program you want with the variable you want and naming it something you'll remember, then put the script in your path.
Here's an example.
Let's use what you suggested, using "ls -a" as the command you want when you type "d". Simply create a text file with your favorite editor that contains the command "ls -a" and name it "d". Then chmod "d" to 755 so that the file is executable and move it to your /bin or /usr/bin directory. This way, "d" does what you want and "ls" still has the ability to use the many variables.
There is a much more complex way to use bash scripting to create a menu for the various "ls" variables, but it's been like 7 years since I did that sort of stuff, so this is simple, doesn't take much space, and it works.
Not quite what im looking for. I didnt think i explained myself correctly, my fault. Let me try one more time. Lets use the elvis editor. Every time i use it i add an option that tells elvis to show the current line and colum at the bottom. So your way would be to put this in a script
elvis -option
-option isnt really the option, its just for example. Using that though, i couldnt specify a file on the command line. What i want is to be able to specify that each time i type "elvis somefile.ext" on the command line and press enter, it would automaticly add the option to it. Is that possible?
I have been tying all night to figure out how to make a simple command alias just to get the idea of how to do it but to no avail. Here's what I've tried: In a text editor I entered "alias exit=bye" saved it made it executable and moved it to my bin directory. Now when I pull up a terminal window and enter bye nothing happens. Where am I going wrong here ?
1) a shell script generally needs a shabang on the first line to specify it's a script (#!/bin/sh)
2) it seems you're declaring the alias backwards..."exit" is a standard command that you assign to an alias.
3) putting "alias bye=exit" in a script doesn't do anything except declare the alias. If you want to use alias, do as crabboy said....you can specify either a function as he wrote, or a command without a function. Then if you wanted to use that alias in a script, you just need to add the alias "bye".
As an example, in ${HOME}/.bashrc, add the line
alias bye=exit
Then you can type "bye" into a terminal and it will close. You could also add bye to a script and it will do the same thing.
.bashrc probably wasn't automatically created.
It's a file placed in your home directory which contains bash configurations specific to your user.
As for where you enter it, it doesn't really matter as long as it is on its own line.
keep in mind that if you have any command options or multiple commands in your alias, it'll need to be quoted:
Code:
alias x='clear; exit'
alias mcd='mount /dev/cdrom'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.