LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-09-2007, 09:26 AM   #1
cornish
Member
 
Registered: May 2005
Location: Sussex, England
Distribution: Ubuntu 7.10
Posts: 131

Rep: Reputation: 15
Very simple script


I use this command sometimes to quickly display an ip address of a host

host hostname | tail -c 15

Rather than typing this command in each time I thought about creating either an alias or a simple script.
For example the alias would be called gh so all I would need to do is type gh [I]hostname[I]

As simple as this sounds I dont know how to create/pass variables can any one help??
 
Old 10-09-2007, 09:39 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Try adding an entry into your .bashrc, in the alias section. alias gh="host <hostname> | tail -c 15".
After making the entry, give the command 'source .bashrc' to reload .bashrc and make the new alias active.
 
Old 10-09-2007, 09:46 AM   #3
cornish
Member
 
Registered: May 2005
Location: Sussex, England
Distribution: Ubuntu 7.10
Posts: 131

Original Poster
Rep: Reputation: 15
Sorry buddy that didnt work
syntax error near unexpected token '|'
 
Old 10-09-2007, 10:04 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
in your .bashrc:
Code:
gethost() {
   host $1 | tail -c 15
}
Then in your shell
Code:
gethost hostname
will output its IP address.

Last edited by pwc101; 10-09-2007 at 10:06 AM.
 
Old 10-09-2007, 11:03 AM   #5
whk
Member
 
Registered: Jun 2005
Posts: 202

Rep: Reputation: 37
Have you tried instead arrow up on the commmand line.
or
Cover 'host | tail -c 15' by holding down the left mouse button and relocate to the command line then press the center (wheel) button.

In a year I would forget what gh is if I don't add a full comment line in the script.

Last edited by whk; 10-10-2007 at 11:18 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
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Help with simple script? chucker8 Solaris / OpenSolaris 1 02-21-2007 10:51 AM
Need help with a simple script shell script WindowBreaker Linux - Software 2 12-15-2005 12:45 PM
Simple script Savahn Programming 2 07-14-2004 05:23 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

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

All times are GMT -5. The time now is 05:36 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
Open Source Consulting | Domain Registration