Go Back   Technology Questions > Software Questions > Operating System Questions > Linux

Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 02-07-2008, 07:11 PM
Eric
Tablet PC Guest
 
Posts: n/a
bash question

How do i do this in one command?
x=$(hostname); echo "${x:5:2}"
I've tried things like:
echo "${$(hostname):5:2}"
echo "${"\$\(hostname\)":5:2}"
and many other variations but bash doesnt like it,
I'm sure there is an easy way, no?
Eric


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

 
Old 02-07-2008, 07:11 PM
Xploder HD Movie Player for PS3. Manage, convert and transfer media files between the PC and PS3.
  #2 (permalink)  
Old 02-07-2008, 08:20 PM
jellybean stonerfish
Tablet PC Guest
 
Posts: n/a
Re: bash question

On Thu, 07 Feb 2008 19:03:53 -0800, Eric wrote:

> How do i do this in one command?
> x=$(hostname); echo "${x:5:2}"


echo "${HOSTNAME:5:2}"

stonerfis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #3 (permalink)  
Old 02-07-2008, 11:30 PM
Eric
Tablet PC Guest
 
Posts: n/a
Re: bash question

jellybean stonerfish wrote:

> On Thu, 07 Feb 2008 19:03:53 -0800, Eric wrote:
>
>> How do i do this in one command?
>> x=$(hostname); echo "${x:5:2}"

>
> echo "${HOSTNAME:5:2}"
>
> stonerfis

That is for an environment variable but what if you wanted the output of a
command? e.g ${<command>:5:2}
Eric

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #4 (permalink)  
Old 02-08-2008, 01:30 AM
pk
Tablet PC Guest
 
Posts: n/a
Re: bash question

Eric wrote:

> jellybean stonerfish wrote:
>
>> On Thu, 07 Feb 2008 19:03:53 -0800, Eric wrote:
>>
>>> How do i do this in one command?
>>> x=$(hostname); echo "${x:5:2}"

>>
>> echo "${HOSTNAME:5:2}"
>>
>> stonerfis

> That is for an environment variable but what if you wanted the output of a
> command? e.g ${<command>:5:2}
> Eric


I think the ${parameter:offset:length} is for variables only.

Maybe something like

command | cut -b 6-7

does the same thing you were trying to do, but without using an extra
variable.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #5 (permalink)  
Old 02-08-2008, 01:30 AM
birre
Tablet PC Guest
 
Posts: n/a
Re: bash question

On 2008-02-08 08:16, Eric wrote:
> jellybean stonerfish wrote:
>
>> On Thu, 07 Feb 2008 19:03:53 -0800, Eric wrote:
>>
>>> How do i do this in one command?
>>> x=$(hostname); echo "${x:5:2}"

>> echo "${HOSTNAME:5:2}"
>>
>> stonerfis

> That is for an environment variable but what if you wanted the output of a
> command? e.g ${<command>:5:2}
> Eric
>


Like this ?
echo $(hostname):5:2

/bb
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #6 (permalink)  
Old 02-08-2008, 01:30 AM
pk
Tablet PC Guest
 
Posts: n/a
Re: bash question

birre wrote:

> On 2008-02-08 08:16, Eric wrote:
>> jellybean stonerfish wrote:
>>
>>> On Thu, 07 Feb 2008 19:03:53 -0800, Eric wrote:
>>>
>>>> How do i do this in one command?
>>>> x=$(hostname); echo "${x:5:2}"
>>> echo "${HOSTNAME:5:2}"
>>>
>>> stonerfis

>> That is for an environment variable but what if you wanted the output of
>> a command? e.g ${<command>:5:2}
>> Eric
>>

>
> Like this ?
> echo $(hostname):5:2


$ echo $(hostname):5:2
kermit:5:2
$

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script glitch Mike Linux 6 08-11-2007 04:30 AM
Printing: OpenOffice yes, bash no. toni Linux 6 06-27-2007 04:30 PM
Bash script questions. Longfellow Linux 5 05-05-2007 11:26 PM
grep in a bash script hobbzilla Linux 4 05-05-2007 11:11 PM
cron.daily bash scripting question Beowulf Linux 2 01-15-2007 12:02 PM


All times are GMT -8. The time now is 03:54 PM.


2003 - 2008 All Rights Reserved. Technology Questions

SEO by vBSEO 3.1.0