I have a script that works perfectly fine, but need to know the use of a command. I was trying to gain some knowledge from the script but I couldn't understand the use of expr in it. 1. expr isn't getting executed, expr "trycnt + 1" -> it gave me output as trycnt + 1 and nowhere in this script it has been used. Just want to understand it.
Siddhesh.K
Last edited by Scott; 06-17-2011 at 05:15 PM..
Reason: Code tags
The use of expr there is simply wrong. Expr works like this:
Each number, symbol, and individual bracket has to be their own, separate parameter to get a sensible result. And even when it works, it only prints the numbers, it doesn't actually alter any variables. You have to put it in backticks to get the number back into the shell(because expr is often not a part of the shell at all) so it's a bit awkward to use.
If you have a shell that supports it, like ksh or bash, you can use the more intuitive (( )) math syntax.
Do u mean to say, that my previous script will not work. So far i have not encountered the failure while stopping the process. It has been clean so far.
what do u suggest? should i use the older script or the new one posted by you.
Do u mean to say, that my previous script will not work. So far i have not encountered the failure while stopping the process. It has been clean so far.
It means that I suggest you read the comments I left when correcting some of your program, and the rest of this thread for that matter. You asked what was wrong with your use of expr, we explained, then you went ahead and did the same wrong way?
Your script may work now but your error checking wasn't doing what you thought it did, if things go wrong I don't know what will happen.
And no, don't blindly use my program. Read the comments I left in it so you can understand my modifications and incorporate what things you think are necessary in your own.
Hello.
System : opensuse leap 42.3
I have a bash script that build a text file.
I would like the last command doing :
print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt
where :
print_cmd ::= some printing... (1 Reply)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
This really puzzles me. The following code gives me the error 'expr: syntax error' when I try to do multi-line comment using here document
<<EOF
echo "Sum is: `expr $1 + $2`"
EOF
Even if I explicitly comment out the line containing the expr using "#", the error message would still exist... (3 Replies)
Hi All,
As per my knowledge in unix, my code looks fine. But still I am getting error (expr:syntax error). Please help me to resolve this error.
Script :
PRE_LBNO=0
PRE_DATE=0
TOT_PAY=0
TOT_REM=0
TOTAL=1
for Record_Type in `cut -c 1 Inputt.dat`
do
if ;
then
CURR_LBNO=` cut -c... (6 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hi Guys,
THis is the first time am using the expr expression.
I like to know how to write the expression a=(b\100)*a.
THis works fine if it gives without a bracket. the bracket should be present as i wanted to define the order of execution.
Help me out.
Thanks for your help in advance.... (2 Replies)
I know I asked a similar question but I want to know if there is a regular expression existing that with a korn shell cmd, finds any timestamp data records in a file where it is greater then a timestamp in a shell variable ?
something like :
grep all records where it has a timestamp >... (5 Replies)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)
I found below script to check whether the variable is a digit in ksh.
############################
#!/bin/ksh
REPLY="3f"
if ]*\)'` != ${REPLY} && "${REPLY}" != "0" ]]
then
print "is digit\n"
else
print "not digit\n"
fi
############################
Although it works fine, but... (6 Replies)