Sponsored Content
Full Discussion: Variable setting help please
Top Forums Shell Programming and Scripting Variable setting help please Post 76376 by bakunin on Tuesday 28th of June 2005 05:38:34 AM
Old 06-28-2005
At least you last version should be working.

Still there are some things to say about:

/switches ranting, style-aficionado mode on

Don't use the backticks any more, this is outdated style and not necessary in the Korn shell. If you want to execute a command, then put the output of that command into a variable instead of

Code:
 x=`command`

use

Code:
 x="$(command)"


Second, instead of "expr" or "let" you should use the "(( .. ))" construct, which is easier to read and encouraged by David Korn. Instead of

Code:
 x=$(expr $x + 1)
and
let x=1

better write:

Code:
 (( x = x + 1)) or (( x+= 1 ))
and
(( x = 1  ))

Yes, I already know i can be a PITA, no neeed to point that out. ;-))

/switches ranting mode off, reverting back to a humble person

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

setting CC variable

I am trying to install GCC-3.1.1 on an SGI Indigo2. I already have MIPSpro 7.2.1 installed. However, when I try to configure GCC-3.1.1, I get the message "cc ERROR: cc -o conftest -g failed, You must set the environment variable CC to a working compiler." What is the name of the MIPSpro c++... (1 Reply)
Discussion started by: mdbanas
1 Replies

2. Programming

setting CC variable

I am trying to install GCC-3.1.1 on an SGI Indigo2. I already have MIPSpro 7.2.1 installed. However, when I try to configure GCC-3.1.1, I get the message "cc ERROR: cc -o conftest -g failed, You must set the environment variable CC to a working compiler." What is the name of the MIPSpro c++... (1 Reply)
Discussion started by: mdbanas
1 Replies

3. UNIX for Dummies Questions & Answers

Setting a variable

I want to set a variable to be any number of dashes. Rather than doing the following: MYVAR="------------------" I'd like to be able to set the variable to, say, 80 dashes but don't want to have to count 80 dashes. Is there a way to do this? (2 Replies)
Discussion started by: photh
2 Replies

4. UNIX for Dummies Questions & Answers

Setting a variable (need syntax help)

I need some syntax help (working in a bash shell) I have a variable which is a filename with an extension, and I need to create another variable with the same name but a different extension To explain, the input file should be called something like "filename.L1" and the output file should be... (1 Reply)
Discussion started by: Slanter
1 Replies

5. Shell Programming and Scripting

Setting variable

How do you set a varible with information that contains a string and also another variable? For example: subject="Attention: $name / This $type needs your attention" The $xxxx are of course other variables that I instantiated earlier. Is it like Java where you have to use double quotes and... (1 Reply)
Discussion started by: briskbaby
1 Replies

6. UNIX for Dummies Questions & Answers

setting a variable

In my script, I have the following command.... du -sk `ls -ltd sales12|awk '{print $11}'`|awk '{print $1}' it returns the value 383283 I want to modify my script to capture that value into a variable. So, I try doing the following... var1=`du -sk `ls -ltd sales12|awk '{print... (5 Replies)
Discussion started by: tumblez
5 Replies

7. Shell Programming and Scripting

Help with setting a variable!

I am working within a while loop and i am trying to set a variable that will read out each count of the files. the problem is the count variable i have set up gives me a total and not the individual count of each file. in the data area there is 4 abc.dat and 1 def.dat. how can i do this??? ... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

8. Programming

Setting Environment variable..!

Hi, I already have one CPP program which invokes the C program.And the C program contains whole function definitions..!This is a working program..I have to enable the logs in both CPP as well as in the C program ..!So I am reading the enviornmental variable log path from the CPP and doing the... (2 Replies)
Discussion started by: Kattoor
2 Replies

9. Shell Programming and Scripting

Setting a variable within if block

Hi, i have a variable which i would like to set inside an if block for example IS_VAR=0 if then IS_VAR=1 fi echo IS_VAR the last echo statement gives 0.So setting variables in the if block doesnt have effect outside the block?Is there any workaround for this? Thanks , Padmini (11 Replies)
Discussion started by: padmisri
11 Replies

10. UNIX for Dummies Questions & Answers

Setting a variable in unix

Hi , Whenever i want to start tomcat server I need to go to <tomcatdir>\bin and execute startup.sh file. How would i make this happen whenever i start my machine? Also want to know How would i set the variable at startup. for example I want to set JAVA_HOME and JRE_HOME whenever the... (3 Replies)
Discussion started by: pinga123
3 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 04:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy