Appending to a file using exec command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending to a file using exec command
# 1  
Old 01-08-2011
Appending to a file using exec command

Hi,

I need the data to be appended to the file using exec command in linux.

I am able to add the data to a file using exec command but the file is getting overwritten.

Quote:
exec >& capture.txt

echo "This will be piped to capture.txt"
Above exec command is used to overwite in a file.

When I use "exec >>& fileName", getting "syntax error near unexpected token `&' and `exec >>& capture.txt'"

Please someone tell me how to append to a file using exec command.
# 2  
Old 01-08-2011
Assuming you are not using a csh-derived shell, then:
Code:
exec >> filename

# 3  
Old 01-08-2011
I want the errors occured in a script should be appended to the file using exec command.
when i run
Quote:
exec >> filename
, errors are displaying in STDOUT.
I want errors to be appended to a file(say log file).
# 4  
Old 01-08-2011
Then just redirect just STDERR:
Code:
exec 2>> filename

or if both STDOUT and STDERR:
Code:
exec >> filename 2>&1

or if using bash:
Code:
exec &>> filename

These are detailed in the bash and ksh manual pages under 'redirection'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

What does the following exec command do it is in the shell file?

I have a shell script, research_dump_sub.sh the first 3 lines are below. the below two lines writing to log file, i am not finding the log file, how to locate, and what is the exec command doing exactly please. and the third line again calling/triggering the shell file. i didn't understood. ... (2 Replies)
Discussion started by: cplusplus1
2 Replies

3. UNIX for Dummies Questions & Answers

appending a command to print a file in a comma delimited format

Hi everyone, i have a file that I had grep'd from something else lets call it file1.txt which consists variable files and lines due to different scenarios/inputs 1782 9182 fe35 ac67 how can I print this in this manner? 1782,9182,fe35,ac67 also if i had piped the new output... (2 Replies)
Discussion started by: prodigy06
2 Replies

4. Shell Programming and Scripting

"exec" command. Stopoutput to file.

I have a script (ksh, Linux) which is about 500 lines and this is only a small requirement. Below is an example of my requirement. FunctionThis(){ echo "You are in this. Goes to log" } FunctionThat(){ echo "You are in That. Goes to log" } FunctionScreen(){ echo "You are in Screen.... (3 Replies)
Discussion started by: edidataguy
3 Replies

5. Shell Programming and Scripting

exec command help

Hi, I have the following lines in a script : . . exec < some_file . . . I have very little idea about exec command. I would like to know what this does and what will happen if the file some_file does not exist. Specifically, I would like to know whether the lines following this... (5 Replies)
Discussion started by: elixir_sinari
5 Replies

6. Shell Programming and Scripting

exec command help

All, I am using below shell script to output the content to outputfile.txt. What I am looking for is in addition to outputfile.txt, I want the output to be on standard output too. exec > outputfile.txt echo "Starting " echo "ending" (5 Replies)
Discussion started by: basic_shell
5 Replies

7. Shell Programming and Scripting

Help with exec command and file descriptors II

Need to close files which descriptor number are larger than 9 in ksh. 'exec 10>&-' fails with 'ksh: 10: not found'. How do you specify file descriptors which occupies two or more digits in ksh script? Thanks, Masaki (2 Replies)
Discussion started by: masaki
2 Replies

8. UNIX for Dummies Questions & Answers

Need help with -exec cp command.

I have a ksh script that contains the following: find /dir1/dir2 -type f -name "FILE.*" -newer /dir1/dir2/afterme.txt -exec cp /dir1/dir2/dir3 {} \; When I run it from the cli, it runs fine. When I run it from the ksh script I get find: missing argument to `-exec' I also tried -exec cp... (40 Replies)
Discussion started by: bbbngowc
40 Replies

9. Shell Programming and Scripting

Help with exec command and file descriptors??

im having trouble with the comprehending the exec command and the use of file descriptors. given: #!/bin/sh exec 4>&1 exec 1>&2 exec 2>&4 exec 4>&- echo Hello would the standard output of this script be sent to STDOUT, STDERR or neither and why??? thanks for the help. (1 Reply)
Discussion started by: rfourn
1 Replies

10. UNIX for Dummies Questions & Answers

using the -exec command

linux redhat 8.0 I am getting accustomed to using the -exec command to get around my databse.. and use it to edit and update files..! is this more apllicable than jumping from one directory to the other.. I have set up the databse so that the inode #'s are accessable and can get me from one... (0 Replies)
Discussion started by: moxxx68
0 Replies
Login or Register to Ask a Question