how to read a variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to read a variable?
# 1  
Old 04-29-2009
how to read a variable?

i want to ask how can i read a variable?

like
Code:
for i in 1 2 3
do
cat file${1} | while read something
do
if [ ]
echo " file name: file${i}" >>temp
else
echo ", file${i}" >>temp
done
done

it is not working, can i do something like that?

actually i want the output below
file name: file1, file2, file3

Last edited by mingming88; 04-29-2009 at 11:59 AM..
# 2  
Old 04-29-2009
can anyone please help me with the question?
Thank you
# 3  
Old 04-29-2009
Please don't up bump up the posts - it's against the rules.
# 4  
Old 04-29-2009
Quote:
Originally Posted by mingming88
i want to ask how can i read a variable?

like
Code:
for i in 1 2 3
do
cat file${1} | while read something
do
if [ ]
echo " file name: file${i}" >>temp
else
echo ", file${i}" >>temp
done
done

it is not working, can i do something like that?

actually i want the output below
file name: file1, file2, file3
Not sure what you are looking for. try this
Code:
echo -n "filename: ";for i in 1 2 3;do echo -n "file${i} ";done

# 5  
Old 04-29-2009
On the cat command - you have ${1} instead of ${i} - that will not do what you seem to want.

Quote:
Originally Posted by mingming88
i want to ask how can i read a variable?

like
Code:
for i in 1 2 3
do
cat file${1} | while read something
do
if [ ]
echo " file name: file${i}" >>temp
else
echo ", file${i}" >>temp
done
done

it is not working, can i do something like that?

actually i want the output below
file name: file1, file2, file3
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script read variable with for

Hi All, How I can read on variable with cycle for in bash script e.g.#!/bin/bash VAR1=`command1 sentence list` for i in $(cat $VAR1); do VAR2=`command2 $i` echo $VAR2 doneSo read VAR1 execute command over this and load in VAR2 then print VAR2, Thanks you, Please wrap... (1 Reply)
Discussion started by: aav1307
1 Replies

2. Linux

Use read to set a variable.

Hi all, I used to set variable by read from keyboard read -p 'Input new value for variable :' var Now I want to pipe from ls and set to var a.txt b.txt c.txt ls | grep a.txt | read var why this cannot set the $var. What is the different between them....:wall: (4 Replies)
Discussion started by: mainsun
4 Replies

3. Shell Programming and Scripting

read variable substitution

Allright so a quick question. I'm building a script that will eventually do a full IP subnet scan. It starts off by first entering an IP address, (capturing host and net ID comes after that) and I want it to use the current IP address if no input is given. Is there a quick way to define the... (1 Reply)
Discussion started by: BisMarc
1 Replies

4. Shell Programming and Scripting

read variable after echo

Hi, i want to create an user-friendly script where you are asked for two numbers. i would like that these two number to be separated with "--" for example, but i can't figure out how to do this. for example read -p "Insert lowest and highest value: " min ; echo -n "-- "; read max so... (3 Replies)
Discussion started by: ezitoc
3 Replies

5. Shell Programming and Scripting

want to read variable for the file

Hi, i have one file which has list of data like this xemp 42 yeet 87 wax 223 dyne 442 i want to read each of in for loop from the script can you give me syntax Use code tags, ty. (2 Replies)
Discussion started by: mail2sant
2 Replies

6. UNIX for Dummies Questions & Answers

How to read a file into a variable?

Hello, I have a ini-file containing comma-separated e-mail addresses, an bash-script sending a mail. Mail-addresses and the mail-script are separated, so I need not to change the important mail script. But how can I read out the file into a variable? It is possible to handover the mail... (7 Replies)
Discussion started by: ABE2202
7 Replies

7. Shell Programming and Scripting

Can I use read to read content of a variable

Can I use the read command to read the contents of a variable? I'm trying by using the following code and getting nothing back. I'm in a Linux environment. #!/bin/ksh IFS=~ VAR1=1~2~3~4 echo $VAR1 | read a b c d print "$a $b $c $d" (9 Replies)
Discussion started by: nmalencia
9 Replies

8. Shell Programming and Scripting

How to read variable with no display

I'll be reading user name and password from the person while running a shell script so that he is authenticated. The challenge here is to read the password variable without displaying on screen. Is there a way? I presently do it displaying it on the screen as echo " please enter your... (9 Replies)
Discussion started by: dayanandra
9 Replies

9. UNIX for Dummies Questions & Answers

Cant read in variable on first try

Hi, My problem is : echo Division read vDivision variable1=`cut -c **something****' echo Do you want to proceed ? read ans I cant seem to read in ans on the first try and have to repeatedly enter the return key. If i remove the ` ` statement its ok but i need that line for... (1 Reply)
Discussion started by: normie
1 Replies

10. UNIX for Advanced & Expert Users

Cannot read in variable using read on first try

Hi, My problem is : echo Division read vDivision variable1=`cut -c **something****' echo Do you want to proceed ? read ans I cant seem to read in ans on the first try and have to repeatedly enter the return key. If i remove the ` ` statement its ok but i need that line for... (1 Reply)
Discussion started by: normie
1 Replies
Login or Register to Ask a Question