Slackware This Forum is for the discussion of Slackware Linux.
|
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
05-30-2003, 08:52 PM
|
#1
|
Member
Registered: Mar 2003
Location: US
Distribution: Kubuntu 6.06
Posts: 173
Rep:
|
A bash alias question
I guess my question is not more of a how to do something as it is why do it one way as apossed to another.
I am trying to reduce some typing at the command prompt by storing large commands in a smaller one. ex: alias off='shutdown -h now' etc. So I have read that you can use aliases for this sort of thing and I was planning on putting these aliases in the profile file that is global for all users.
Another way(the way I have done this before) I was planning on doing this is to put the following in the profile file ex: off='shutdown -h now' and then run this command at the bash prompt by typing the following $off.
Which way is the correct or most accepted way of doing things? If you can set shell variables to values(like I have done in the 3rd paragraph) why use alias? In what situation would you use a shell variable as opposed to an alias? Thanks.
|
|
|
05-30-2003, 09:13 PM
|
#2
|
Member
Registered: Dec 2002
Location: St. Louis, MO
Distribution: Slackware 9.1
Posts: 482
Rep:
|
All the linux and unix books I've read say they're for the purpose of not having to type long commands in.
|
|
|
05-31-2003, 10:15 AM
|
#3
|
Member
Registered: Mar 2003
Location: US
Distribution: Kubuntu 6.06
Posts: 173
Original Poster
Rep:
|
But why would you use one method as opposed to another?
|
|
|
05-31-2003, 10:34 AM
|
#4
|
Member
Registered: Dec 2002
Location: St. Louis, MO
Distribution: Slackware 9.1
Posts: 482
Rep:
|
No idea.
|
|
|
05-31-2003, 10:50 AM
|
#5
|
Senior Member
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,306
Rep:
|
you can quickly check any aliases with
alias, but if you throw those variables in with
all those export statements, they can be much harder
to find, besides that it is easier to type the command
without the $ in front.
|
|
|
06-02-2003, 12:49 PM
|
#6
|
Senior Member
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
|
use alias, that's what it's for.
|
|
|
06-03-2003, 09:22 AM
|
#7
|
Member
Registered: May 2003
Location: Upstate NY, U.S.
Distribution: Slackware
Posts: 248
Rep:
|
Yes, alias is the method that was invented for this purpose. Setting environment variables is for handing information about the way your system is set up, or the state it is currently in, to running programs.
|
|
|
06-03-2003, 10:15 AM
|
#8
|
Senior Member
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571
Rep:
|
Speaking of aliases..
Where do you put your alias assignments?
For my root user I created a .bash_profile file and put
alias ls="ls --color"
So, far this is the only alias I have.
|
|
|
06-03-2003, 10:39 AM
|
#9
|
Senior Member
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,306
Rep:
|
i use this one more than anything
alias c='cd ..;ls'
since i used dos for years before unix, i have a bunch
that match dos commands, like
alias dir='ls -l'
alias move='mv -i'
alias xcopy='cp -rv'
but i never need these anymore. i'm always typing
du, ls, rm and such in windows instead.
another possible use of them is to use ways
you commonly mistype things such as
sl='ls'
for me
fdsik for fdisk
i think the proper place for these is .bashrc
|
|
|
06-03-2003, 12:48 PM
|
#10
|
Member
Registered: May 2003
Posts: 161
Rep:
|
Quote:
Originally posted by whansard
another possible use of them is to use ways
you commonly mistype things such as
sl='ls'
for me
fdsik for fdisk
|
You can enable command spelling correction with a
set correction = cmd (correct commands only)
or
set correction = all (correct command and/or filenames)
if you use tcsh.
|
|
|
06-03-2003, 02:08 PM
|
#11
|
Senior Member
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,306
Rep:
|
i've tried setting up tcsh and zsh before, but i never
could get either the way i liked.
That's a good idea though. I'm sure most newbies
don't know about most of the abilities of the different
shells.
|
|
|
06-03-2003, 07:09 PM
|
#12
|
Member
Registered: Mar 2003
Location: US
Distribution: Kubuntu 6.06
Posts: 173
Original Poster
Rep:
|
ok, thats good to know, I will use alias for these commands. I am putting mine in /etc/profile so that they are global for all users.
|
|
|
All times are GMT -5. The time now is 07:47 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|