Reading a string and passing passing arguments to a while loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a string and passing passing arguments to a while loop
# 15  
Old 01-15-2012
Hi, what does echo $SHELL give? What shebang are you using in your script? On Solaris /bin/sh is not a POSIX shell, you should use /usr/xpg4/bin/sh instead or use bash.
# 16  
Old 01-15-2012
Quote:
Originally Posted by Scrutinizer
Hi, what does echo $SHELL give? What shebang are you using in your script? On Solaris /bin/sh is not a POSIX shell, you should use /usr/xpg4/bin/sh instead or use bash.
echo $SHELL gives me
Quote:
/bin/ksh.
But my shebang is
Quote:
/usr/bin/bash
# 17  
Old 01-15-2012
Could you post a copy of the script exactly like you are using it?
# 18  
Old 01-15-2012
Quote:
Originally Posted by Scrutinizer
Could you post a copy of the script exactly like you are using it?
Code:
 
function function1{
...
}
function 2{
...
}
for i in $( cat param.cfg | grep -v "^#" | grep ':' )
                             do
                                printf "$n. $i \t"
                                n=`expr $n + 1`
                             done
                             echo Please enter START     
                            read START
                            echo Please enter STOP
 read STOP
STOP=`expr $STOP - $START + 1`
n=$START
                             for i in $( cat rparam.cfg | tail +$START | head -$STOP | grep -v "^#" | grep ':' )
                             do
                                     echo "$n. $i"
                                     n=`expr $n + 1`
                             done
OLDIFS=$IFS
                                   IFS=":"
linenr=0
                                while IFS=: read x y z ; do
                                  linenr=$((linenr+1));
                                  [ $linenr -ge $RESPONSE ] || continue
                                  [ $linenr -le $RESPONSESTOP  ] || break
                                  case $x in
                                    \#*) continue
                                  esac
                                  function1
                                done < param.cfg

The functions above are standard and it doesnt interfere with the o/p of the while loop. The main part of the code is as above. I've removed all the formattin echo's thats not relevant to the logic

---------- Post updated at 01:22 PM ---------- Previous update was at 01:16 PM ----------

A sample output of the above shell for different options is:

START=2 STOP=9
Code:
RED:value2:Y
RED:value3:Y
BLUE:value4:Y
RED:value5:Y
RED:value6:Y
BLUE:value7:Y
BLUE:value8:Y

START =5 STOP=12
Code:
RED:value5:Y
RED:value6:Y
BLUE:value7:Y
BLUE:value8:Y


START =12 STOP=24
Code:
RED:value12:Y
RED:value13:Y

START =21 STOP=34
Code:

Nothing is displayed
# 19  
Old 01-15-2012
Hi, where do $RESPONSE and $RESPONSESTOP get set?
# 20  
Old 01-15-2012
Quote:
Originally Posted by Scrutinizer
Hi, where do $RESPONSE and $RESPONSESTOP get set?
I am very sorry Scrutinizer. RESPONSE = START; RESPONSESTOP=STOP
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to avoid "Too many arguments" error, when passing a long String literal as input to a command?

Hi, I am using awk here. Inside an awk script, I have a variable which contains a very long XML data in string format (500kb). I want to pass this data (as argument) to curl command using system function. But getting Too many arguments error due to length of string data(payloadBlock). I... (4 Replies)
Discussion started by: cool.aquarian
4 Replies

2. Shell Programming and Scripting

Using here document when passing arguments

I have a script test.sh which reads various inputs from a user. #!/bin/ksh read x read y read z echo x: $x y: $y z: $z # read few more things again read a read b echo a: $a b: $b When i run this script as test.sh << EOF 1 2 EOF (3 Replies)
Discussion started by: ariesb2b
3 Replies

3. Shell Programming and Scripting

Passing arguments that contain space

hi All, i am trying to pass arguments that contain space , value will be stored in variables to be used further in script , i went thru previous posting , still its not clear to how to implement for my case. passing 3 args test.sh it is 'fun to work in unix' inside shell ... (3 Replies)
Discussion started by: gvkk
3 Replies

4. Shell Programming and Scripting

Passing arguments to csh

I have noticed this thing using csh when passing arguments Suppose I call a csh script using ../Scripts/plot-model.csh -vmod="npt02-z30.vmod" -R="0/80/0/30" -c="0/4.5" -aspr="1:10" Somehow the " get removed when doing $argv ending up with -vmod=npt02-z30.vmod... (0 Replies)
Discussion started by: kristinu
0 Replies

5. UNIX for Dummies Questions & Answers

Passing arguments

I need to pass arguments to a shell script.My batch is calling some java program. ################# x=$1 y=$2 java -classpath program ################### if first parameter and second parameter is null then java -classpath program if first parameter is not null and second parameter is... (3 Replies)
Discussion started by: mnjx
3 Replies

6. Shell Programming and Scripting

Passing arguments to the subshell

I have a shell script which is invoked by passing an argument. The outer shell script calls another subshell and I want the argument passed down to flow down to the subshell. E.g Invoking a shell ======>> abc_refresh.ksh NM Below is the content of abc_refresh.ksh Value1=$1... (7 Replies)
Discussion started by: Mihirjani
7 Replies

7. Shell Programming and Scripting

passing arguments

Hi I have a script to which I pass multiple arguments, for example lets say the script name is "abc". I run the script like ./abc def /file <directory location> In the above "def" is the first argument and "/file" is the second argument. I expect <directory location> that is passed after... (4 Replies)
Discussion started by: zmfcat1
4 Replies

8. Shell Programming and Scripting

Passing Arguments-Help

Hi, I have a script which adds the user credentials to an ldap server. Im passing the variables as below.. /path/my_script $uname $pwd $environ ${deposit} If i enter some special characters like ';' in $pwd, script returns an error which is set to display if the user enters... (5 Replies)
Discussion started by: Tuxidow
5 Replies

9. Shell Programming and Scripting

passing in arguments into a file using a loop

Hi, so Im a bit new to shell scripting and want to do the following but not sure how. Basically I have a file named "output" which contains misc text but inside the file I want to set up variables like $1 or some symbol. Anyways, in another file called "list" I have a list of items that I want to... (11 Replies)
Discussion started by: eltinator
11 Replies

10. UNIX for Dummies Questions & Answers

passing arguments

I'm trying to pass a filename, or all the files in the current directory to the ls command with a script. Unsuccessful so far, here are a few of my attempts: #!/bin/ksh read fname #if (( $# > 0 )); then $fname | ls -l #fi this produces a long listing of all the files in my current... (4 Replies)
Discussion started by: jpprial
4 Replies
Login or Register to Ask a Question