| |||
| 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 |
| |||
| 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 |
| |||
| 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. |
| |||
| 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 |
| |||
| 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 $ |
![]() |
| Bookmarks |
| Thread Tools | |
| |
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 |