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, 10: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, 10:39 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
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, 10: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, 11: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 11:06 AM.
 
Old 10-09-2007, 12:03 PM   #5
whk
Member
 
Registered: Jun 2005
Posts: 202

Rep: Reputation: 35
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 12:18 PM.
 
  


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 05:19 AM
Help with simple script? chucker8 Solaris / OpenSolaris 1 02-21-2007 11:51 AM
Need help with a simple script shell script WindowBreaker Linux - Software 2 12-15-2005 01:45 PM
Simple script Savahn Programming 2 07-14-2004 06:23 PM
Simple C Shell script is not so simple elconde Programming 2 09-17-2001 12:53 AM


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