LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Very simple script (https://www.linuxquestions.org/questions/linux-newbie-8/very-simple-script-590532/)

cornish 10-09-2007 09:26 AM

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??

bigrigdriver 10-09-2007 09:39 AM

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.

cornish 10-09-2007 09:46 AM

Sorry buddy that didnt work
syntax error near unexpected token '|'

pwc101 10-09-2007 10:04 AM

in your .bashrc:
Code:

gethost() {
  host $1 | tail -c 15
}

Then in your shell
Code:

gethost hostname
will output its IP address.

whk 10-09-2007 11:03 AM

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.


All times are GMT -5. The time now is 08:11 AM.