LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-30-2003, 08:52 PM   #1
CodeWarrior
Member
 
Registered: Mar 2003
Location: US
Distribution: Kubuntu 6.06
Posts: 173

Rep: Reputation: 30
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.
 
Old 05-30-2003, 09:13 PM   #2
snocked
Member
 
Registered: Dec 2002
Location: St. Louis, MO
Distribution: Slackware 9.1
Posts: 482

Rep: Reputation: 30
All the linux and unix books I've read say they're for the purpose of not having to type long commands in.
 
Old 05-31-2003, 10:15 AM   #3
CodeWarrior
Member
 
Registered: Mar 2003
Location: US
Distribution: Kubuntu 6.06
Posts: 173

Original Poster
Rep: Reputation: 30
But why would you use one method as opposed to another?
 
Old 05-31-2003, 10:34 AM   #4
snocked
Member
 
Registered: Dec 2002
Location: St. Louis, MO
Distribution: Slackware 9.1
Posts: 482

Rep: Reputation: 30
No idea.
 
Old 05-31-2003, 10:50 AM   #5
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,306

Rep: Reputation: 66
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.
 
Old 06-02-2003, 12:49 PM   #6
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
use alias, that's what it's for.
 
Old 06-03-2003, 09:22 AM   #7
Rodrin
Member
 
Registered: May 2003
Location: Upstate NY, U.S.
Distribution: Slackware
Posts: 248

Rep: Reputation: 31
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.
 
Old 06-03-2003, 10:15 AM   #8
itsjustme
Senior Member
 
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571

Rep: Reputation: 47
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.
 
Old 06-03-2003, 10:39 AM   #9
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,306

Rep: Reputation: 66
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
 
Old 06-03-2003, 12:48 PM   #10
phishman3579
Member
 
Registered: May 2003
Posts: 161

Rep: Reputation: 32
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.
 
Old 06-03-2003, 02:08 PM   #11
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,306

Rep: Reputation: 66
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.
 
Old 06-03-2003, 07:09 PM   #12
CodeWarrior
Member
 
Registered: Mar 2003
Location: US
Distribution: Kubuntu 6.06
Posts: 173

Original Poster
Rep: Reputation: 30
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.
 
  


Reply


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
setting alias in bash, permanently allelopath Linux - General 6 10-24-2008 04:10 AM
Alias question (2 commands for one alias) gflores Linux - Newbie 3 01-21-2006 12:40 AM
bash ls --color alias? tripmix Linux - Newbie 7 01-18-2005 04:49 AM
alias in bash shell wincrk Linux - General 12 07-20-2004 12:35 PM
bash and alias kleptos Slackware 6 01-23-2003 08:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:47 AM.

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
Open Source Consulting | Domain Registration