| Author |
How to use expr command?
|
|
|
| Hi,
How to get the value 3 from tty(/dev/pts/3) using expr command?
| |
| Stachu 'Dozzie' K. 2006-11-27, 8:01 am |
| On 27.11.2006, CKS <ckmsasi@gmail.com> wrote:
> Hi,
> How to get the value 3 from tty(/dev/pts/3) using expr command?
Why do you want to use expr? This can be done with shell-only
statement:
$ tty=/dev/pts/3
$ echo ${tty#/dev/pts/}
(assume that there is /dev/pts/... in $tty).
--
<Kosma> Niektórzy lubią dozziego...
<Kosma> Oczywiście szanujemy ich.
Stanislaw Klekot
| |
| Stephane CHAZELAS 2006-11-27, 8:01 am |
| 2006-11-27, 03:20(-08), CKS:
> Hi,
> How to get the value 3 from tty(/dev/pts/3) using expr command?
var="tty(/dev/pts/3)"
expr "$var" : 'tty(.*/\(.*\))$'
--
Stéphane
| |
| Bruce Barnett 2006-11-27, 8:01 am |
| "CKS" <ckmsasi@gmail.com> writes:
> Hi,
> How to get the value 3 from tty(/dev/pts/3) using expr command?
>
How's this:
a=/dev/pts/3
expr substr $a 10 2
--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
| |
| Bill Marcum 2006-11-27, 8:01 am |
| On 27 Nov 2006 03:20:44 -0800, CKS
<ckmsasi@gmail.com> wrote:
> Hi,
> How to get the value 3 from tty(/dev/pts/3) using expr command?
>
man basename
--
I have a hard time being attracted to anyone who can beat me up.
-- John McGrath, Atlanta sportswriter, on women weightlifters.
| |
| Antonio Maschio 2006-11-29, 4:02 am |
| Stephane CHAZELAS wrote:
> 2006-11-27, 03:20(-08), CKS:
>
> var="tty(/dev/pts/3)"
> expr "$var" : 'tty(.*/\(.*\))$'
>
Can you explain this regexp in detail?
-- Antonio
| |
| Stephane CHAZELAS 2006-11-29, 4:02 am |
| 2006-11-29, 09:46(+01), Antonio Maschio:
> Stephane CHAZELAS wrote:
> Can you explain this regexp in detail?
[...]
tty(.*/\(.*\))$
tty( matches the "tty(" string at the beginning (there's an
implicit "^" with expr).
..*/: any number of character up to "/" (as many as possible so
up the rightmost "/")
\(.*\))$: the remaining characters followed by ")" that has to
be the last character of the string ($). The part in \(...\) is
captured and returned by expr followed by a newline character.
--
Stéphane
| |
| Antonio Maschio 2006-11-30, 4:10 am |
| Stephane CHAZELAS ha scritto:
> 2006-11-29, 09:46(+01), Antonio Maschio:
> [...]
>
> tty(.*/\(.*\))$
>
> tty( matches the "tty(" string at the beginning (there's an
> implicit "^" with expr).
>
> .*/: any number of character up to "/" (as many as possible so
> up the rightmost "/")
> \(.*\))$: the remaining characters followed by ")" that has to
> be the last character of the string ($). The part in \(...\) is
> captured and returned by expr followed by a newline character.
>
well, thanks
-- Antonio
|
|
|
|