LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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


Reply
  Search this Thread
Old 02-23-2010, 11:09 AM   #1
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Rep: Reputation: 146Reputation: 146
How do you create a BASH shortcut?


Say I wanted to do this:
Code:
ssh root@10.10.10.10
How would I create a shortcut in BASH so that I can simply type:
Code:
mypc
And have it do the same thing?

I want to be able to execute commands like that; like you can with ls, cd, grep, etc.

Do I create a BASH script and place it in /bin?

Thanks.
 
Old 02-23-2010, 11:12 AM   #2
jwl17330536
Member
 
Registered: Feb 2010
Location: Raleigh, NC
Posts: 83

Rep: Reputation: 22
man alias

or google alias..
 
1 members found this post helpful.
Old 02-23-2010, 11:12 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
A "shortcut" is often just a link. You have at least two options:

1. A link (soft or hard)---look at "man ln" for the details.

2. An alias. I think this fits your situation better. See "man alias" for details.

And of course, you can always create a script.....
 
Old 02-23-2010, 11:14 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by jwl17330536 View Post
man alias

or google alias..
I LIKE it!!!---so much more concise than mine...
 
Old 02-23-2010, 11:17 AM   #5
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 146Reputation: 146
Quote:
Originally Posted by pixellany View Post
A "shortcut" is often just a link. You have at least two options:

1. A link (soft or hard)---look at "man ln" for the details.

2. An alias. I think this fits your situation better. See "man alias" for details.

And of course, you can always create a script.....
No manual entry for alias. {Ubuntu 9.10}

@jwl17330536

Sorry I did not know that is what you called it.

@pixellany So the BASH script in /bin would work or is there something wrong or stupid about that?

Thanks.
 
Old 02-23-2010, 11:23 AM   #6
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 146Reputation: 146
Googled it.

alias mypc=ssh root@10.10.10.10

would work? Is that correct syntax?

Thanks.
 
Old 02-23-2010, 11:24 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
No "alias" command in Ubuntu---you have got to be kidding!!

Try searching for alias like so:
Code:
sudo find / -name "*alias*"
(This will find any file on the hard drive whose name contains "alias". If nothing is found, check the package manager.

WAIT!!--maybe "alias" is a built-in. try just typing "alias" in a terminal.

Quote:
@pixellany So the BASH script in /bin would work or is there something wrong or stupid about that?
The is nothing wrong or stupid about a script--unless of course it's not written correctly....
 
Old 02-23-2010, 11:29 AM   #8
jwl17330536
Member
 
Registered: Feb 2010
Location: Raleigh, NC
Posts: 83

Rep: Reputation: 22
Quote:
Originally Posted by leopard View Post
No manual entry for alias. {Ubuntu 9.10}
www.google.com does (I promise you that it is very easy. I am just not going to do your google search for you and tell you. I don't remember the exact command. [Sadly])

Quote:
Originally Posted by leopard View Post
@pixellany So the BASH script in /bin would work or is there something wrong or stupid about that?
Again, I promise you that an alias is way easier!
 
Old 02-23-2010, 11:31 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by leopard View Post
No manual entry for alias. {Ubuntu 9.10}
Indeed not. You have to look at man bash, since alias is a shell built-in. I'd not consider the possibility to make scripts for this kind of task. Aliases are enough for simple tasks and shell functions are even better for more complex task and for a bunch of other reasons (take a look at the Advanced Bash Scripting Guide for details, chapters 23 and 24).

You can define your own aliases in ~/.bashrc so that they will be available every time you start an interactive shell session. Moreover if you prefer to have a separate file to define aliases and/or functions, you can follow the Ubuntu advice (see in ~/.bashrc) and create a file named .bash_aliases. Don't forget to un-comment the relevant lines in ~/.bashrc in that case:
Code:
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Last edited by colucix; 02-23-2010 at 11:32 AM.
 
Old 02-23-2010, 11:37 AM   #10
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,133

Rep: Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876
Quote:
Originally Posted by leopard View Post
Googled it.

alias mypc=ssh root@10.10.10.10

would work? Is that correct syntax?

Thanks.
i think it mite need quotes
 
Old 02-23-2010, 11:47 AM   #11
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Guess what?

"man alias" works here. But alias also shows up in "man bash"
 
Old 02-23-2010, 11:56 AM   #12
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 146Reputation: 146
Post #6

Quote:
Originally Posted by leopard View Post
Googled it.

alias mypc=ssh root@10.10.10.10

would work? Is that correct syntax?

Thanks.
Post #8

Quote:
www.google.com does (I promise you that it is very easy. I am just not going to do your google search for you and tell you. I don't remember the exact command. [Sadly])
Why did you say that? I have never knew of alias in BASH. Tis' why I came here. I always try to do it for myself. Try googling 'how to bash shortcuts' and look for mention of 'alias'. Thanks.

Quote:
You can define your own aliases in ~/.bashrc so that they will be available every time you start an interactive shell session. Moreover if you prefer to have a separate file to define aliases and/or functions, you can follow the Ubuntu advice (see in ~/.bashrc) and create a file named .bash_aliases. Don't forget to un-comment the relevant lines in ~/.bashrc in that case:
Code:

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Good Info! I did a quick "man bash | grep alias" and it turned up plenty useful info. Thank you!
 
Old 02-23-2010, 12:49 PM   #13
jwl17330536
Member
 
Registered: Feb 2010
Location: Raleigh, NC
Posts: 83

Rep: Reputation: 22
Quote:
Originally Posted by leopard View Post
Why did you say that? I have never knew of alias in BASH. Tis' why I came here. I always try to do it for myself. Try googling 'how to bash shortcuts' and look for mention of 'alias'.
I said it because I had already told you that it was "alias" that you were looking for. I believe you that 'how to bash shortcuts' doesn't mention 'alias'... I was not trying to be rude it is just that I had already given you the name of the command that you needed. Myself, if I cannot find the man page locally then the first thing I do is seek the online man page. I just assumed that everyone did also.

Side Note: man alias works on my box
 
Old 02-23-2010, 01:04 PM   #14
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
man alias works for me, it says it's part of the POSIX programmers manual. I'm pretty sure it's a bash built-in.

As for the OP, add this to your .bashrc file:

alias mypc='ssh root@10.10.10.10'

Last edited by MTK358; 02-23-2010 at 01:06 PM.
 
Old 02-24-2010, 09:36 PM   #15
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Original Poster
Rep: Reputation: 146Reputation: 146
Talking I'm back, sorry; had school

Quote:
Originally Posted by MTK358 View Post
man alias works for me, it says it's part of the POSIX programmers manual. I'm pretty sure it's a bash built-in.

As for the OP, add this to your .bashrc file:

alias mypc='ssh root@10.10.10.10'
Thanks! That did the trick, very quick and easy.

I'll mark this thread as SOLVED and thank all of you via the button, but I would like to show you guys something.

I know 'man alias' worked for all of you; but it DID NOT work for me. I attached a screenshot to prove it.

Anyways thanks everyone

Last edited by lupusarcanus; 03-07-2010 at 02:20 AM.
 
  


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
how to create a send to shortcut nkd Linux - Desktop 2 10-24-2008 03:03 AM
How to create shortcut in Applications sandy1234sa Linux - Software 1 03-04-2008 03:17 AM
How to create a shortcut? gmoney Linux - Software 3 10-08-2003 07:51 PM
create a shortcut/alias allelopath Linux - Software 6 04-01-2003 09:45 AM
How to create shortcut in Linux ? futurist Linux - General 2 03-21-2003 01:20 AM

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

All times are GMT -5. The time now is 02:41 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