Re: Are there any substring in unix command
From: Alan Connor (xxxxxx_at_xxxx.xxx)
Date: Tue, 12 Aug 2003 18:55:26 GMT
On 12 Aug 2003 18:13:19 GMT, Chris F.A. Johnson <firstname.lastname@example.org> wrote:
> On Tue, 12 Aug 2003 at 18:04 GMT, Alan Connor wrote:
>> On 12 Aug 2003 17:32:25 GMT, Chris F.A. Johnson <email@example.com> wrote:
>>> On Tue, 12 Aug 2003 at 08:59 GMT, Ooops wrote:
>>>> Dear all,
>>>> If i have a string ABCD/DEFG, how can i get ABCD only without /DEFG?
>>> With any Bourne-type shell, and using no external commands:
>>> set x $str
>>> echo $2
>> The best solution offered, but ----->
>> Why did you do it as above instead of:
>> str=ABCD/DEFG; IFS=/; set $str; echo $1
>> which gives the same output?
> I put one command per line so that it is easier to read and modify.
> I use "set x $str" in case $str is empty or starts with "-":
> $ q='-s e r'
> $ set $q
> bash: set: -s: invalid option
> set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
> Try it yourself with "q=''".
Aren't we the comedian :-)
I about jumped out of my skin!
(it's a LONG file, well-padded with functions and stuff....)
> I use "set x $str" rather than "set -- $str" because it is more
> portable; older shells do not recognize "--".