Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 03-28-2011, 09:45 PM   #1
LQ Newbie
Registered: Mar 2011
Location: Pittsburgh, PA
Posts: 5

Rep: Reputation: 0
Question Desire trick to modify hostname in shell script

I am looking an neat trick / elegant solution to
manipulate / modify hostname and set a variable to the
value inside a script. I have figured what I want to do.
I just want to know how to set the variable correctly ?

Say my host name is 'machine005' (w/o single quotes)

So the hostname command would be


fine. If I want to change the first '0' to a '9' then

hostname|sed 's/0/9/' <-- (produces)

So I would like to set the command string in bold
above to be the value of a variable inside a string.

Does the following do this

setenv VAR "hostname|sed \'s/0/9/\'"

It seems that Double/Single quotes don't play nice
together. So I am trying to figure this out.

Any assistance would be appreciated.

Old 03-28-2011, 10:21 PM   #2
LQ Newbie
Registered: Mar 2011
Location: Pittsburgh, PA
Posts: 5

Original Poster
Rep: Reputation: 0
Lightbulb Viola!

I found this works (on Cygwin)

Var=`hostname|sed 's/0/9/'`

This would produce in post above hostname=machine901.




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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] need help to modify output of shell script raggmopp1961 Programming 2 12-04-2010 03:26 AM
how to modify a line of a file using shell script? shayori Linux - Newbie 9 04-16-2010 03:44 AM
bash Shell script to modify DNS zone file KinnowGrower Programming 4 12-12-2009 09:07 PM
shell script to batch process-modify ip numbers in files. SupermanInNY Programming 5 08-13-2009 04:03 AM
modify content in a file using shell script fjkum Linux - Newbie 2 08-03-2006 05:46 AM > Forums > Linux Forums > Linux - General

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration