control variables...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting control variables...
# 1  
Old 01-07-2010
control variables...

Hi.

I´ve a question to a running script:

Code:
i=0                                                                                                                                    #fill an Array with all files in a folder ending with .sys
for Par in *.sys ; do
    Par2[$i]="$Par" ;
    i=$((i + 1)) ;
done
 
#fill the "control variable" with the value of the Array
a=${Par2[0]} ; b=${Par2[1]} ; c=${Par2[2]}; d=${Par2[3]}; e=${Par2[4]}; f=${Par2[5]}; g=${Par2[6]}; h=${Para[7]}; i=${Par2[8]}; 
 
#remove the file extension (.sys) for each control variable (a,b,c,...)
a=`echo $a | sed 's/\(.*\).sys/\1/'` ; b=`echo $b | sed 's/\(.*\).sys/\1/'` ; c=`echo $c | sed 's/\(.*\).sys/\1/'`; #...
 
echo "simulation models"
echo "---------------------------------------"
echo " $a "
echo " $b "
echo " $c "
#...
echo " $i "
sleep 2
 
        echo " ++---------------------------------+"
        echo " || 01 (TI+MM) --> calculate all (a-i)"  
        echo " || 02 (TI+MM) --> calculate $a   "
        echo " || 03 (TI+MM) --> calculate $b   "
        echo " || 03 (TI+MM) --> calculate $c   "
        #...
        echo " || 09 (TI+MM) --> calculate $i   "
 
   read ANTW
   case $ANTW in
 
01) command1
02) command2
03) command3
#...
09) command 9
 
 
esac

The script works, but its really big and i think that it can rephrase in a better way retaining the functions unchanged.
Another problem is, that the variables in my script go from a to i. So if there are for example 50 .sys-files in the folder it ignores the last 41.

I´ll be glad for each advice...

Thanks a lot
Lock3
# 2  
Old 01-07-2010
hm without trying it out, use something like:

Code:
echo *sys | sed 's/\.sys$//g' | read a b c d e f g h i




Edit: ok, here the definition for an unlimited number of files
Code:
set -A arr $(ls *sys | sed 's/\.sys//g')

you don't have to use a b c d, just use
Code:
echo " || 02 (TI+MM) --> calculate ${arr[0]}   "

for example

Last edited by funksen; 01-07-2010 at 07:14 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to pass variables into anothother variables?

Below are three variables, which I want to pass into variable RESULT1 username1=userid poihostname1=dellsys.com port1=8080 How can I pass these variables into below code... RESULT1=$((ssh -n username1@poihostname1 time /usr/sfw/bin/wget --user=sam --password=123 -O /dev/null -q... (4 Replies)
Discussion started by: manohar2013
4 Replies

2. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

3. Shell Programming and Scripting

Reading control characters into variables

Hi, I am trying to write a shell script to help with some digital signature work currently being undertaken where we have a file that contains a number of rows ending with ^M. What I need to do is concatenate this using shell scripting and retain the control character. E.G. abc^M... (5 Replies)
Discussion started by: chris01010
5 Replies

4. Shell Programming and Scripting

BASH arrays and variables of variables in C++

Sometimes it is handy to protect long scripts in C++. The following syntax works fine for simple commands: #define SHELLSCRIPT1 "\ #/bin/bash \n\ echo \"hello\" \n\ " int main () { cout <<system(SHELLSCRIPT1); return 0; } Unfortunately for there are problems for: 1d arrays:... (10 Replies)
Discussion started by: frad
10 Replies

5. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

6. UNIX for Dummies Questions & Answers

For loop control with two variables in csh shell

Hi All How can i control for loop with two different variables in csh shell Regards Nikhil (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

7. Shell Programming and Scripting

control click variables

I want to be able to control click (Mac) and be able to select from a context menu...run file....and have it dynamically run based on the control click. How do I get the control click absolute path of the filename? Are there different variables like directory, fullpath, extention? (0 Replies)
Discussion started by: mainegate
0 Replies

8. UNIX for Dummies Questions & Answers

Using Variables for Bandwidth control

Hi, I am very new to scripting and have a question regarding variables and their use in a bandwidth monitoring script. I have identified a few primary variables being; Bandwidth CIR Download=32kbits <- these match as per the script below Bandwidth PIR Download=96kbits Bandwidth CIR... (1 Reply)
Discussion started by: vinnir
1 Replies

9. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

10. Shell Programming and Scripting

naming variables with variables

Hello, FIRST QUESTION: I am writing a script in which a query is taken at the beginning of the script to be later used at the end. In the query, variables are generated from a loop, and I would like to assign the variable NAME (not value) with an appended 1, 2, 3, 4.....n. The number of... (2 Replies)
Discussion started by: Allasso
2 Replies
Login or Register to Ask a Question