Sponsored Content
Top Forums Shell Programming and Scripting Preserving values with for loop for later use Post 302740101 by Corona688 on Wednesday 5th of December 2012 02:00:13 PM
Old 12-05-2012
That would be ugly, glitch-prone, and a gaping security hole(never use eval), which is why I suggested the alternative.

This could work, if your variables don't have more than one line in them.

Code:
printf "%s\n" "$var1" "$var2" "$var3" > save

for X in var1 var2 var3
do
        read $X
done < save

rm -f save

But again, the best way would be to avoid the problem completely by using a subshell -- that's one reason they exist. Or just don't overwrite those variables in the first place.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

while read loop preserving leading whitespace

Hi all, I've been trying to get this to work for ages to no avail. I've searched this site and googled but cannot find a satisfactory answer. I've got a while loop, like this while read line do echo "$line" done < file_name Now, my problem is that most of the lines in the file... (3 Replies)
Discussion started by: zazzybob
3 Replies

2. Shell Programming and Scripting

getting values from variable in a loop

I have a set of variables: f1="./someFolder" . . f10="./someOtherFolder" And I'm trying to use the following loop for (( i = 0; i <= 10; i++ )) do temp=f$i done I'm trying the get the values from my set of variable to make directories, but I can't seem the get those value... (3 Replies)
Discussion started by: kriuz
3 Replies

3. Shell Programming and Scripting

How to use array values after the loop.

- I m retreving values from database and wish to use those values later in my shell script. I m placing these values in an array da_data but outside loop array is empty.Problem is its treating array as local inside loop hence array is empty outside loop. Plz go through the script and suggest how... (1 Reply)
Discussion started by: Devesh5683
1 Replies

4. Shell Programming and Scripting

adding values with a loop

Hi there, I am checking disk spaced used on a box # df -k | grep dsk | awk {'print $3'} 2055463 20165785 18310202 32274406 I want to somehow add them up but am no quite sure how to do this in a loop. ...i.e for n in 'df -k | grep dsk | awk {'print $3}' do <some adding... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

5. Shell Programming and Scripting

Preserving whitespace in a for loop

I obviously haven't learned my lesson with shell and whitespace. find /path/to/some/where/ -name "*.pdf" | awk '{print $5}'| uniq -d results: some Corporation other Corporate junk firmx Works fine from cmdline but the whitespace turns into another FS in a for loop. for... (7 Replies)
Discussion started by: s_becker
7 Replies

6. UNIX for Dummies Questions & Answers

For loop returning more values

Hi All, Thanks all of you for the help you provide to me. Well, I have one more problem, where I am trying to pull file system information in the loop and display the filesystem percentege. I am using following code to achive this, nut it's giving the weired output. My file system is ... (1 Reply)
Discussion started by: alok.behria
1 Replies

7. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

8. Shell Programming and Scripting

While loop to read values

Hi Everyone, I am currently tasked with some reporting on various Unix based OSes. I have a script deployed that runs and grabs the information I am looking for, and has a bit of logic to output the desired result into a text file. Example of my text file: multiUsers=yes... (1 Reply)
Discussion started by: Zaphod_B
1 Replies

9. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

10. Shell Programming and Scripting

Variable values within for loop

Hi All I am trying to fetch the size of three files into three separate variables within a for loop and am doing something like this: for i in ATT1 ATT2 ATT3 do size_$i=`ls -ltr $i | awk '{print $5}'` echo ${size_$i} done but am getting the below error: ksh: size_ATT1=522: not... (3 Replies)
Discussion started by: swasid
3 Replies
QAxScript(3qt)															    QAxScript(3qt)

NAME
QAxScript - Wrapper around script code SYNOPSIS
This class is part of the Qt ActiveQt Extension. #include <qaxscript.h> Inherits QObject. Public Members enum FunctionFlags { FunctionNames = 0, FunctionSignatures } QAxScript ( const QString & name, QAxScriptManager * manager ) ~QAxScript () bool load ( const QString & code, const QString & language = QString::null ) QStringList functions ( FunctionFlags flags = FunctionNames ) const QString scriptCode () const QString scriptName () const QAxScriptEngine * scriptEngine () const QVariant call ( const QString & function, const QVariant & var1 = QVariant ( ), const QVariant & var2 = QVariant ( ), const QVariant & var3 = QVariant ( ), const QVariant & var4 = QVariant ( ), const QVariant & var5 = QVariant ( ), const QVariant & var6 = QVariant ( ), const QVariant & var7 = QVariant ( ), const QVariant & var8 = QVariant ( ) ) QVariant call ( const QString & function, QValueList<QVariant> & arguments ) Signals void entered () void finished () void finished ( const QVariant & result ) void finished ( int code, const QString & source, const QString & description, const QString & help ) void stateChanged ( int state ) void error ( int code, const QString & description, int sourcePosition, const QString & sourceText ) DESCRIPTION
This class is defined in the Qt ActiveQt Extension, which can be found in the qt/extensions directory. It is not included in the main Qt API. The QAxScript class provides a wrapper around script code. Every instance of the QAxScript class represents a piece of scripting code in a particular scripting language. The code is loaded into the script engine using load(). Functions declared in the code can be called using call(). The script provides scriptEngine() provides feedback to the application through signals. The most important signal is the error() signal. Direct access to the QAxScriptEngine is provided through the scriptEngine() function. Warning: This class is not available with the bcc5.5 and MingW compilers. Member Type Documentation QAxScript::FunctionFlags This FunctionFlags enum describes formatting for function introspection. QAxScript::FunctionNames - Only function names are returned. QAxScript::FunctionSignatures - Returns the functions with signatures. MEMBER FUNCTION DOCUMENTATION
QAxScript::QAxScript ( const QString & name, QAxScriptManager * manager ) Constructs a QAxScript object called name and registers it with the QAxScriptManager manager. This is usually done by the QAxScriptManager class when loading a script. A script should always have a name. A manager is necessary to allow the script code to reference objects in the application. The manager takes ownership of the object. QAxScript::~QAxScript () Destroys the object, releasing all allocated resources. QVariant QAxScript::call ( const QString & function, const QVariant & var1 = QVariant ( ), const QVariant & var2 = QVariant ( ), const QVariant & var3 = QVariant ( ), const QVariant & var4 = QVariant ( ), const QVariant & var5 = QVariant ( ), const QVariant & var6 = QVariant ( ), const QVariant & var7 = QVariant ( ), const QVariant & var8 = QVariant ( ) ) Calls function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8 as arguments and returns the value returned by the function, or an invalid QVariant if the function does not return a value or when the function call failed. See QAxScriptManager::call() for more information about how to call script functions. QVariant QAxScript::call ( const QString & function, QValueList<QVariant> & arguments ) This is an overloaded member function, provided for convenience. It behaves essentially like the above function. Calls function passing arguments as parameters, and returns the result. Returns when the script's execution has finished. See QAxScriptManager::call() for more information about how to call script functions. void QAxScript::entered () [signal] This signal is emitted when a script engine has started executing code. void QAxScript::error ( int code, const QString & description, int sourcePosition, const QString & sourceText ) [signal] This signal is emitted when an execution error occured while running a script. code, description, sourcePosition and sourceText contain information about the execution error. void QAxScript::finished () [signal] This signal is emitted when a script engine has finished executing code. void QAxScript::finished ( const QVariant & result ) [signal] This is an overloaded member function, provided for convenience. It behaves essentially like the above function. result contains the script's result. This will be an invalid QVariant if the script has no return value. void QAxScript::finished ( int code, const QString & source, const QString & description, const QString & help ) [signal] This is an overloaded member function, provided for convenience. It behaves essentially like the above function. code, source, description and help contain exception information when the script terminated. QStringList QAxScript::functions ( FunctionFlags flags = FunctionNames ) const Returns a list of all the functions in this script if the respective script engine supports introspection; otherwise returns an empty list. The functions are either provided with full prototypes or only as names, depending on the value of flags. See also QAxScriptEngine::hasIntrospection(). bool QAxScript::load ( const QString & code, const QString & language = QString::null ) Loads the script source code written in language language into the script engine. Returns TRUE if code was successfully entered into the script engine; otherwise returns FALSE. If language is empty (the default) it will be determined heuristically. If code contains the string End Sub it will be interpreted as VBScript, otherwise as JScript. Additional scripting languages can be registered using QAxScript::registerEngine(). This function can only be called once for each QAxScript object, which is done automatically when using QAxScriptManager::load(). QString QAxScript::scriptCode () const Returns the script's code, or the null-string if no code has been loaded yet. See also load(). QAxScriptEngine * QAxScript::scriptEngine () const Returns a pointer to the script engine. You can use the object returned to connect signals to the script functions, or to access the script engine directly. QString QAxScript::scriptName () const Returns the name of the script. void QAxScript::stateChanged ( int state ) [signal] This signal is emitted when a script engine changes state. state can be any value in the QAxScriptEngineState enumeration. SEE ALSO
http://doc.trolltech.com/qaxscript.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qaxscript.3qt) and the Qt version (3.3.8). Trolltech AS 2 February 2007 QAxScript(3qt)
All times are GMT -4. The time now is 05:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy