Computing.Net > Forums > Unix > Expr Quoting

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Expr Quoting

Reply to Message Icon

Name: Derek King
Date: October 15, 2003 at 03:43:11 Pacific
OS: Unixware7
CPU/Ram: Intel
Comment:

Hi,

Can anyone help?

Heres what i'm trying to achieve.
a=degz.log

return the part of the string "degz"

here's where i'm at.
a=degz.log
b=`expr index $a "." - 1`
c=`expr substr $a 1 $b`

What I would like to do is substitute $b in the last command for the expr index command, however i'm sure i'm getting something incorrect with my quoting ( or lack of it! )

The command I would like would look something like:
a=degz.log
b=`expr substr $a 1 `expr index $a "." - 1``

Can anyone point me in the right direction please.

Regards
Degz.



Sponsored Link
Ads by Google

Response Number 1
Name: Frank
Date: October 15, 2003 at 05:18:04 Pacific
Reply:

Derek,

don't know if I got you right but if you only woul like to get the degz than you can use echo ${a%%.log}

No Risk no Fun

Frank



0

Response Number 2
Name: Derek King
Date: October 15, 2003 at 06:44:44 Pacific
Reply:

Hi,
If I try that I get ERROR:bad substitution.

I'm using a bourne shell, and also the "degz" part of the string can be any length.

Cheers for any help.


0

Response Number 3
Name: WilliamRobertson
Date: October 15, 2003 at 16:10:30 Pacific
Reply:

${var%pattern} is Korn shell. (%% matches all occurrences, % just the first; likewise ## and # match from the left.)

Also in bash you could use

echo ${a/%.log}

/bin/sh is often just a link to either /bin/ksh or /bin/bash these days so I'm not sure what the original 'classic' Bourne shell can do (probably not much).


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


scripts to merge file ver... What is PReS ?



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Expr Quoting

unix script problem cant get expr www.computing.net/answers/unix/unix-script-problem-cant-get-expr-/5828.html

how to generate from 1 to 254 www.computing.net/answers/unix/how-to-generate-from-1-to-254/4054.html

Script Problem www.computing.net/answers/unix/script-problem/2556.html