Continue output redirection on the same line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Continue output redirection on the same line?
# 1  
Old 11-14-2008
Continue output redirection on the same line?

I have
Code:
for i in 1 2 3 4
do
  echo $i >> test.txt
done

test.txt contains ...
Code:
1
2
3
4

But I want it to contain ...
Code:
1234

Any suggestions?
# 2  
Old 11-14-2008
How about:
Code:
line=""
for i in 1 2 3 4
do
  line=$line$i
done
echo $line >> test.txt

# 3  
Old 11-14-2008
You can add a \c to the end of echo.

echo "$i\c" >> test.txt
# 4  
Old 11-16-2008
Or even simpler (tested on bash and zsh):

printf "%d" {1..4} > file

Kind regards
Chris
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add new line after 'continue' in if statment

Hello, im creating a csv file for email reporting on issues. my problem is that after 'continue' command in if statment in a loop the new paramter writing into the log doesnt take new line. timeout 4s zabbix_get -I $ZBX -p $PORT -s $IP -k "system.run" if ; then ... (3 Replies)
Discussion started by: batchenr
3 Replies

2. Shell Programming and Scripting

output redirection

Hi all I was wondering if there was a slicker way of doing this without the file - awk '{print $2}' FS=":" "${FILE}" > "${TMPFILE}" { read M_GRP_ID || m_fail 1 "Error: Read failed 1 (${FUNCNAME})" read M_GRP_WAIT || m_fail 1 "Error: Read failed 2 (${FUNCNAME})" }... (6 Replies)
Discussion started by: steadyonabix
6 Replies

3. Shell Programming and Scripting

Redirection of ls -l output

Hi I am making a script where i want to redirect the output of ls -l to a file Example #ls -l fil1.txt > /opt/temp/a.txt ac: No such file or directory I want to capture output of this command like here output is ac: No such file or directory can anyone help (4 Replies)
Discussion started by: anish19
4 Replies

4. Shell Programming and Scripting

Continue an instruction on more than one line in a script shell ?

Hello, I have a very long instruction to write, but, for lisibility reasons, I would like to cut it on more than one line and comment each lines. is it possible ? thanks :b: (1 Reply)
Discussion started by: shadok
1 Replies

5. UNIX for Dummies Questions & Answers

Output redirection

Hello i am trying to write a script that will redirect the output to a certain file. Here is the code so far: #!/bin/bash ps -e | sort | more > psfile When I execute the script nothing happens since i assume the output was redirected to the file called psfile. When I try to look at the... (1 Reply)
Discussion started by: mfruiz34
1 Replies

6. Shell Programming and Scripting

Output redirection

We have an application here that does some table queries and then prints the result on screen. I do not have the code of this application (which i will just call "queryCommand"), but what it does is that you call it with some parameters and it prints some info about the query and then the... (5 Replies)
Discussion started by: jolateh
5 Replies

7. Shell Programming and Scripting

Redirection output

Hi there I have a script that runs but it outputs everything onto the screen instead of a file. I've tried using the > outputfile.txt however all it does is dump the output to the screen and creates an outputfile.txt but doesn't put anything in that file. Any help would be appreciated ... (6 Replies)
Discussion started by: kma07
6 Replies

8. Shell Programming and Scripting

Line in bash script to wait for x feedbacks and then continue

I have a script that runs a console/terminal command on the server and what is want is for each of the multiple success reports fed back from the clients (echo-ed out onto the conosle) to be counted and after x number of reports reboot the server. The Details: The command (program) is... (0 Replies)
Discussion started by: dp123
0 Replies

9. Shell Programming and Scripting

redirection and output

I'm redirecting the output of a command to a logfile, however, if the user is on a terminal I would also like the output to be displayed on the screen. tar tvf some_tarfile >Logfile if the user is on a term then have the output to the Logfile and also be displayed on the screen at the same... (2 Replies)
Discussion started by: nck
2 Replies

10. Shell Programming and Scripting

continue line in perl script

HI , I am new to the perl , I am using a if condition and in that if condition i am checking 7 variables value. so it continue to second line .And if i user "\" for the continue line it showing error. Example : if(a >9 || b>8 || c> 10 \ d > 11) { print(); } The above statement is... (3 Replies)
Discussion started by: julirani
3 Replies
Login or Register to Ask a Question