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
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.
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).
Summary: Hi: Around the expr statements, you are using single quotes instead of the back tic, ` #!/bin/bash echo -n "enter name" read uname echo -n "enter number of adult tickets" read atickets echo -n "enter...
Summary: save the followin into a file, like do_fping, then chmod u+x do_fping. This script should let you simply enter an ip address, and do the fping for every IP that has a smaller number than xxx.xxx.xxx....
Summary: Per tom's suggestion, if the grep succeeds at finding something, it will return a status of zero (true), otherwise status of 1. But we first need to nail down the grep. As is, grep [0-9] is satisfied ...