[Solved] <<EOF error checking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] <<EOF error checking
# 1  
Old 11-08-2010
[Solved] <<EOF error checking

I am trying to check the return status of a command thats encapsulated
in an <<EOF

Code:
#!/bin/ksh
set -x
xxx()
{
set -x
ls -lt /tmp/jdlkewjdlkewjdlkewjdlewjdlew<<EOT
ret=$?
EOT
echo "ret=$ret"
} >>$LOG 2>&1

LOG=/tmp/t2.out
rm -rf $LOG
echo "Starting process `date +"%Y-%m-%d-%H:%M:%S"`" >> $LOG
xxx
echo "Ending process `date +"%Y-%m-%d-%H:%M:%S"`" >> $LOG

As you can see from the set -x output (below) this file does not
exist and when I execute $? from the commnad line I get back a non zero.

Can somebody show me how to get back the return status when something is encapulated in <<EOF


Code:
Starting process 2010-11-08-12:39:53
+ ls -lt /tmp/jdlkewjdlkewjdlkewjdlewjdlew
+ 0<<
ret=0
/tmp/jdlkewjdlkewjdlkewjdlewjdlew: No such file or directory
+ echo ret=
ret=
Ending process 2010-11-08-12:39:53

---------- Post updated at 12:52 PM ---------- Previous update was at 12:44 PM ----------

Please ignore I figured it out, placed $? out of EOF
# 2  
Old 11-08-2010
Thanks for letting us know...

All the best
# 3  
Old 11-08-2010
<<EOF just transfers the following lines to a file in /tmp and then redirects stdin (<) to it, so $? is just as valid. It just reads funny with <<EOF on the cmd line (so I use echo '...'|). Here is a truss / tusc of a ksh doing this:
Code:
$ truss -fp ksh -c 'while read l
do
 lsum=$(( $lsum + $l))
done <<! ; echo $? ; echo $lsum
1
2
3
!
'
[22593] execve("/usr/bin/ksh", 0x7b0f11a4, 0x7b0f11b4) ... = 0 [32-bit]
 .
 .
 .
[22593] open("/tmp/sh22593.1", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
[22593] write(3, "1 \n2 \n3 \n", 6) ...................... = 6
[22593] close(3) ......................................... = 0
[22593] fcntl(0, F_DUPFD, 10) ............................ = 10
[22593] fcntl(10, F_GETFD, 0) ............................ = 0
[22593] fcntl(10, F_SETFD, 1) ............................ = 0
[22593] open("/tmp/sh22593.1", O_RDONLY|O_LARGEFILE, 01) . = 3
[22593] fcntl(0, F_GETFD, 0) ............................. = 0
[22593] close(0) ......................................... = 0
[22593] fcntl(3, F_DUPFD, 0) ............................. = 0
[22593] close(3) ......................................... = 0
[22593] sigprocmask(SIG_BLOCK, 0x7b0f2c20, 0x7b0f2c00) ... = 0
[22593] sigprocmask(SIG_SETMASK, 0x7b0f2c00, NULL) ....... = 0
[22593] fcntl(0, F_GETFL, 0) ............................. = 2048
[22593] lseek(0, 0, SEEK_CUR) ............................ = 0
[22593] ioctl(0, TCGETATTR, 0x40004b90) .................. ERR#25 ENOTTY
[22593] sigprocmask(SIG_BLOCK, 0x7b0f2b60, 0x7b0f2b40) ... = 0
[22593] read(0, "1 \n2 \n3 \n", 1024) .................... = 6
 .
 .
 .
[22593] read(0, 0x400059b0, 1024) ........................ = 0
 .
 .
 .
[22593] fcntl(0, F_GETFD, 0) ............................. = 0
[22593] close(0) ......................................... = 0
[22593] fcntl(10, F_DUPFD, 0) ............................ = 0
[22593] close(10) ........................................ = 0
[22593] fcntl(0, F_SETFD, 0) ............................. = 0
[22593] unlink("/tmp/sh22593.1") ......................... = 0
[22593] sigprocmask(SIG_BLOCK, 0x7b0f15a0, 0x7b0f1580) ... = 0
[22593] sigprocmask(SIG_SETMASK, 0x7b0f1580, NULL) ....... = 0
0
6
[22593] write(1, "0 \n6 \n", 4) .......................... = 4
[22593] exit(0) .......................................... WIFEXITED(0)
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

bash error checking problems[solved]

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to make a script called showtime that displays the current time for a given city. The problem is on... (6 Replies)
Discussion started by: kevin298
6 Replies

2. Shell Programming and Scripting

Error with EOF when used in function

Hi all I am inserting record in oracle database using shell script. When the sql part is directly written in the shell script the record is getting inserted. But when the same piece of code is added into a function, I am getting an error while execution "line 45: syntax error: unexpected end of... (6 Replies)
Discussion started by: sudeep.id
6 Replies

3. UNIX for Advanced & Expert Users

tar: write error: unexpected EOF

tar: write error: unexpected EOF I usually encounter this when I'm doing backup to Dat72 tape. Here's the command gzip all files in a directory then tar cvfp /dev/rmt/0n files. Not all files are copied. Any things I should look at? Directory size? ---------- Post updated at 05:20 PM... (1 Reply)
Discussion started by: lhareigh890
1 Replies

4. Shell Programming and Scripting

help pls getting EOF error

#!/bin/bash while : do clear echo ""***************************************" echo "* - MAIN - MENU - *" echo "***************************************" echo "* 1. Directory Listing *" echo "* 2. Users Currently Logged In *" echo "* 3. Create a... (2 Replies)
Discussion started by: celtic123
2 Replies

5. Shell Programming and Scripting

bash: checking file size -solved

Hello I have srv RHEL5, file system UTDM (EMC DiskXtender Unix/Linux File System Manager 3.5 & EMC Centera). it all works under the scheme: have disk is formatted with a file system UTDM, drive open network - NFS, it write data, then migrate the data in the repository - EMC Centera. There are... (0 Replies)
Discussion started by: moskovets
0 Replies

6. UNIX for Dummies Questions & Answers

Unclosed EOF (error)

I have a script which throws an error: "here document `EOF' unclosed" The script is: ... main() { RETVAL=`sqlplus -s $ConnectDetails << EOF SET SERVEROUTPUT ON DECLARE errnum NUMBER; errmsg VARCHAR2(1000); BEGIN My_Procedure( errbuf => errmsg, errcode... (2 Replies)
Discussion started by: laiko
2 Replies

7. Programming

EOF checking the below

Hi, I am practicing exercise programs with System calls. Exercise Question: write a pogram to accept a filename from the user. The program should write ecery fifth byte of the file to the standard output. My Program : # include <stdio.h> # include <fcntl.h> # include <error.h> ... (10 Replies)
Discussion started by: ramkrix
10 Replies

8. UNIX for Advanced & Expert Users

tar:read error: unexpected EOF

I need archive data from some tar files. I use the command "tar xvf filename". For about half of the files I get the error message "tar:read error: unexpected EOF". The number of bytes extracted comes very close to the size of the tar file. An example: 972434779 Jan 10 01:01... (4 Replies)
Discussion started by: mikeruth
4 Replies

9. Shell Programming and Scripting

Unexpected eof error

Hi, I am newbie and am just trying to connect to oracle from shell script ,,,but I am getting the following error ./prog.sh: line 20: syntax error: unexpected end of file The scripts is : #!/bin/bash O=$IFS; IFS=","; while read a b c d do echo $c ... (6 Replies)
Discussion started by: thana
6 Replies

10. UNIX for Dummies Questions & Answers

tar: write error: unexpected EOF

I am taring to disk and get this message: tar: write error: unexpected EOF This message is normally associated with tape devices, not disk. Here is the syntax: tar -cf <tarfilename> /dir Have you seen this message on disk tars? (4 Replies)
Discussion started by: jabe
4 Replies
Login or Register to Ask a Question