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
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
The script echos each token seperately. Use echo -n $i
inside do ... done
.
i have replaced ' ' characters to '' with sed global replace and there is no new line on output of script thanks for help
to read a file using shell, use while read loop
while read -r loop
do
case "$line" in
*]* ) echo $line;;
esac
done <"file"
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....