Sponsored Content
Top Forums Shell Programming and Scripting Whats the error in this script ? Post 302444429 by alister on Wednesday 11th of August 2010 11:29:37 PM
Old 08-12-2010
There's really no need for that eval. A simple command substitution will do (with perhaps a variable to hold the result of expr for clarity's sake).

Code:
arg=`expr $1 - 1`
p=`fact $arg`

Or with any posix-compliant sh:
Code:
p=$(fact $(expr $1 - 1))

Or your example:
Quote:
Originally Posted by agama
If you were using Ksh or bash, the eval statement becomes a bit less muddled:

Code:
p=$( fact $(( $1 - 1)) )

which is also posix-compliant.

Regards,
Alister

Last edited by alister; 08-12-2010 at 12:35 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

whats the purpose of the following script?

whats the purpose of the following script? who could run it? To what is the script refering that exceeds 75%? The mailbox? What does sed 's/%//' do? (1 Reply)
Discussion started by: vrn
1 Replies

2. Shell Programming and Scripting

Whats wrong with this script?

Hi all, #!/bin/ksh BIN=/interface/Gunner age=$1 directory="$2" && directory=. cd "$directory" || exit 1 from=`$BIN/today -$age` cd $BIN for i in `cat filestoarchive.txt`;do cd $i find . -mtime 14 | grep -v '.tar$' | $BIN/dttmfilter | awk '$1<="'$from'"{ print;};' | \ done (2 Replies)
Discussion started by: kayarsenal
2 Replies

3. UNIX for Advanced & Expert Users

Whats wrong in this Script ???

PATH="/clocal/mqbrkrs/user/mqsiadm/sanjay" MAIL_RECIPIENTS="xyz@abc.com" Subject="File accessed in last minutes:" find $PATH -type f -amin -1 > temp.txt.$$ cat temp.txt.$$ | \ while read line do fuser -uV $line >> tempmail.txt done cat "$tempmail.txt" | mailx -s "$Subject"... (4 Replies)
Discussion started by: varungupta
4 Replies

4. UNIX for Dummies Questions & Answers

Whats wrong in the script?

if then if then echo "fst argument is $1 " else if then "fst argument is $1" fi fi fi Can anyone tell me. My requirement is tht pass a string .. Check whether it contains "-". If yes then check if it... (1 Reply)
Discussion started by: nehagupta2008
1 Replies

5. Shell Programming and Scripting

Whats the error in this script

#!/bin/sh #usblcd clear while true; do tail -1 /root/Myprogs/apurva.log > /root/Download/usr/bin/output.txt cat /root/Download/usr/bin/output.txt | echo `awk '{if ($3 == "Connection"&&$4 == "Established") print"Connection Established "} else if {($3 == "DTNCO"&&$4 ==" Sent" && $5="Packet")... (2 Replies)
Discussion started by: appu1987
2 Replies

6. Shell Programming and Scripting

Whats the problem whit my script???

I want to take the even-numbered lines from a file and put them in a separate file and the same thing with the odd-numbered lines. #!/bin/bash file=$1 awk ' { if ( NR % 2 == 0) { (( getline < "$file" ) > "even.txt" )} else { (( getline < "$file" ) > "odd.txt" )} } ' $file (4 Replies)
Discussion started by: cristi2008
4 Replies

7. Shell Programming and Scripting

whats error in code ??

if `egrep -c "safe_mode" /usr/local/lib/php.ini` - gt 0 && " `egrep -c "safe_mode" /usr/local/lib/php.ini` = "On" " then echo " Good " exit else echo " Not Good "; fi and (4 Replies)
Discussion started by: x-zer0
4 Replies

8. Shell Programming and Scripting

Whats wrong with my script?

I am trying to find a value within a properties file and declare it into a variable. Script below. I want the "memSize" to be the branch from the properties file. Right now it always tells me "Not found" What am I doing wrong? #!/bin/sh memsize =''; memSize=`sed '/^\#/d'... (8 Replies)
Discussion started by: vsekvsek
8 Replies

9. OS X (Apple)

Whats wrong with this shell script!!!!!

hi guys can you tell me if anything is wrong with this script, seems reasonable to me but somehow never works. Script redacted for being too explicit (2 Replies)
Discussion started by: Freddo
2 Replies

10. Shell Programming and Scripting

Sh Script whats wrong?

Hi there, i have a problem i have created followning sh files some years ago but now it dosen`t work anymore i never used it a long time. Can anyone find the Error? Its always runs the stop() block and trying to Killing the Server also if i try to start or creat a new one. #!/bin/sh stop()... (6 Replies)
Discussion started by: NewCannon
6 Replies
control(n)						     Tcl Control Flow Commands							control(n)

__________________________________________________________________________________________________________________________________________________

NAME
control - Procedures for control flow structures. SYNOPSIS
package require Tcl 8.2 package require control ?0.1.3? control::control command option ?arg arg ...? control::assert expr ?arg arg ...? control::do body ?option test? control::no-op ?arg arg ...? _________________________________________________________________ DESCRIPTION
The control package provides a variety of commands that provide additional flow of control structures beyond the built-in ones provided by Tcl. These are commands that in many programming languages might be considered keywords, or a part of the language itself. In Tcl, con- trol flow structures are just commands like everything else. COMMANDS
control::control command option ?arg arg ...? The control command is used as a configuration command for customizing the other public commands of the control package. The com- mand argument names the command to be customized. The set of valid option and subsequent arguments are determined by the command being customized, and are documented with the command. control::assert expr ?arg arg ...? When disabled, the assert command behaves exactly like the no-op command. When enabled, the assert command evaluates expr as an expression (in the same way that expr evaluates its argument). If evaluation reveals that expr is not a valid boolean expression (according to [string is boolean -strict]), an error is raised. If expr evalu- ates to a true boolean value (as recognized by if), then assert returns an empty string. Otherwise, the remaining arguments to assert are used to construct a message string. If there are no arguments, the message string is "assertion failed: $expr". If there are arguments, they are joined by join to form the message string. The message string is then appended as an argument to a callback command, and the completed callback command is evaluated in the global namespace. The assert command can be customized by the control command in two ways: [control::control assert enabled ?boolean?] queries or sets whether control::assert is enabled. When called without a boolean argument, a boolean value is returned indicating whether the control::assert command is enabled. When called with a valid boolean value as the boolean argument, the control::assert command is enabled or disabled to match the argument, and an empty string is returned. [control::control assert callback ?command?] queries or sets the callback command that will be called by an enabled assert on assertion failure. When called without a command argument, the current callback command is returned. When called with a command argument, that argument becomes the new assertion failure callback command. Note that an assertion failure callback command is always defined, even when assert is disabled. The default callback command is [return -code error]. Note that control::assert has been written so that in combination with [namespace import], it is possible to use enabled assert com- mands in some namespaces and disabled assert commands in other namespaces at the same time. This capability is useful so that debugging efforts can be independently controlled module by module. % package require control % control::control assert enabled 1 % namespace eval one namespace import ::control::assert % control::control assert enabled 0 % namespace eval two namespace import ::control::assert % one::assert {1 == 0} assertion failed: 1 == 0 % two::assert {1 == 0} control::do body ?option test? The do command evaluates the script body repeatedly until the expression test becomes true or as long as (while) test is true, depending on the value of option being until or while. If option and test are omitted the body is evaluated exactly once. After nor- mal completion, do returns an empty string. Exceptional return codes (break, continue, error, etc.) during the evaluation of body are handled in the same way the while command handles them, except as noted in LIMITATIONS, below. control::no-op ?arg arg ...? The no-op command takes any number of arguments and does nothing. It returns an empty string. LIMITATIONS
Several of the commands provided by the control package accept arguments that are scripts to be evaluated. Due to fundamental limitations of Tcl's catch and return commands, it is not possible for these commands to properly evaluate the command [return -code $code] within one of those script arguments for any value of $code other than ok. In this way, the commands of the control package are limited as compared to Tcl's built-in control flow commands (such as if, while, etc.) and those control flow commands that can be provided by packages coded in C. An example of this difference: % package require control % proc a {} {while 1 {return -code error a}} % proc b {} {control::do {return -code error b} while 1} % catch a 1 % catch b 0 BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category control of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. SEE ALSO
break, continue, expr, if, join, namespace, return, string, while KEYWORDS
assert, control, do, flow, no-op, structure control 0.1.3 control(n)
All times are GMT -4. The time now is 11:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy