using readline with parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using readline with parameter
# 1  
Old 12-11-2011
using readline with parameter

dear all,
i have code shell like this but i want to using parameter for this shell how i can do that :
Code:
ex ./sample.sh 100 500

sample.sh
Code:
START=${1}
LAST=${2}

for (( a=${START}; a<=${LAST}; a++ ))
do
{
        echo $a
}
done

thx for your advice
# 2  
Old 12-11-2011
for-loop in C-style aren't posix standard. Try one of the following options:

Code:
for i in {100..500}
do
    echo $a
done

Code:
a=100
while [ $a -le 500 ]
do
    echo $a
    a=$(($a + 1))
done

# 3  
Old 12-11-2011
Quote:
Originally Posted by balajesuri
for-loop in C-style aren't posix standard. Try one of the following options:

Code:
for i in {100..500}
do
    echo $a
done

Code:
a=100
while [ $a -le 500 ]
do
    echo $a
    a=$(($a + 1))
done

@balajsuri thx for your replay but i dont want using insert variable in scrpit but using parameter for inserting like my exampleSmilie
# 4  
Old 12-11-2011
Code:
a=$1
while [ $a -le $2 ]
do
    echo $a
    a=$(($a + 1))
done

If you insist on using C-style for loops, here's an example:
Code:
for (( i=$1; i<=$2; i++ ))
do
    echo $i
done

# 5  
Old 12-11-2011
Quote:
Originally Posted by balajesuri
Code:
a=$1
while [ $a -le $2 ]
do
    echo $a
    a=$(($a + 1))
done

If you insist on using C-style for loops, here's an example:
Code:
for (( i=$1; i<=$2; i++ ))
do
    echo $i
done

good... whats difference if using while read line and while only iam stillnot understand with this difference
# 6  
Old 12-11-2011
while read <var_name> --> read contents from a file line by line. For e.g. you have a file input.dat with following contents:
AAAA
BBBB
CCCC

The following while loop will read the file line by line and echo it:
bash code:
  1. while read x
  2. do
  3.     echo $x
  4. done < input.dat
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Trouble compiling program using the readline library.

Hi: in the info page for readline library I read -- Function: void rl_variable_dumper (int readable) Print the readline variable names and their current values to `rl_outstream'. If READABLE is non-zero, the list is formatted in such a way that it can be made part of an... (1 Reply)
Discussion started by: stf92
1 Replies

2. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

3. Shell Programming and Scripting

How do I get my shell back to normal readline?

I just ran an application that crashed... but before it did, it managed to set readline echo off, and probably a bunch of other settings. Is there any way I can just tell my shell to re-initialize? To get back to whatever state existed before my shell got messed up by this evil program? (2 Replies)
Discussion started by: jjinno
2 Replies

4. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

5. Programming

Error:readline() on closed filehandle Perl

Hi, i have run the below perl code and i am getting an error Error:readline() on closed filehandle OR at run.pl line 31. CODE: =========================================== open OR,$ARGV; while (<OR>) { # find the batch date next if length $_ < 3; # BLANK LINE # last if $. > 120; #... (3 Replies)
Discussion started by: pspriyanka
3 Replies

6. Programming

Readline programming

Hi, I am new to using readline library to my application. Please I want to no how to write code for command line switches(options), i.e when i press tab the option of command as to change. eg: ls -a ls -d ...so on ls as many options, here i want options to be completed using tab ... (9 Replies)
Discussion started by: vanid
9 Replies

7. Shell Programming and Scripting

Readline Formatting

Hi All, I have a function that loops through an XML file line by line and spits it the content out to a new file (sometimes certain lines need changing). This all works fine, however the formatting of the original XML is not kept. for example:- <?xml version="1.0"?> <mysqldump>... (3 Replies)
Discussion started by: robfwauk
3 Replies

8. Programming

Readline problems

I'm having problems with libreadline. When I write text longer than the current line, the text wraps back to the beginning of the line rather than to the next line. Also, when I use the arrow keys to edit something in that beginning part, it won't display at all (so I can edit only if I remember... (5 Replies)
Discussion started by: CRGreathouse
5 Replies

9. Shell Programming and Scripting

cat vs head vs readline get variable from txt file

I have a file with a single filename in it, which I want to assign to a BASH variable, so I've been trying: c=$(head -1 somefile) echo $c which outputs correctly, but them when I do ... somecommand $c it says it can't find the file, is that because it's grabbing the whole line, and... (5 Replies)
Discussion started by: unclecameron
5 Replies

10. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies
Login or Register to Ask a Question