tags:

views:

57

answers:

4

i have bash script such as


for i in `echo a [ matched.lines`
do
echo $i
done

why output of this script below

a

[

matched.lines


i want output text as it is

a [ matched.lines


how can i do that

thanks for help

+2  A: 

The script echos each token seperately. Use echo -n $i inside do ... done.

but this time there is no new line on output :(
soField
just append a trailing `echo' to the program.
ShiDoiSi
what do you mean with trailing echo ?
soField
...done ; echo
ShiDoiSi
A: 

i have replaced ' ' characters to '' with sed global replace and there is no new line on output of script thanks for help

soField
A: 

to read a file using shell, use while read loop

while read -r loop
do
 case "$line" in 
  *]* ) echo $line;;
 esac
done <"file"
ghostdog74
A: 

Sorry but that's not going to do what you want it to. Your for loop is using a space as a delimiter to it's arguments. This will cause each one of the item's to echo on a seperate line. Adding a -n doesn't work here because you will not get the \n at the end of the line. Honestly I don't see what it is your trying to do here. If you just want to echo this "a [ matched.lines" as a string you can do this:


for i in "a [ matched.lines";do
  echo $i
done

But I feel you're going to misunderstand how to use a for loop....

rcarson