How to print exit status in AWK

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print exit status in AWK
# 1  
Old 12-04-2009
How to print exit status in AWK

Hi all,

How can I print the exit status in AWK?

echo $? doesnt work for me

# 2  
Old 12-04-2009
Awk has an exit command (or statement, call it what you will)..

$ echo blah | awk '{exit 13}'
$ echo $?

Or did you mean something else?
# 3  
Old 12-05-2009
$ #!/bin/nawk -f
$ BEGIN { FS=",";

$ if (ARGC ==1)
$ {print "You need 2 arguments on the command line"}
$ echo "Error" | awk '{exit 13}'
$ echo $?

$ }

How do i have an exit status returned when the number of commandline arguments is 1. The above script does not work
# 4  
Old 12-05-2009
$ cat Test
#!/usr/bin/awk -f
BEGIN { FS=",";
  if (ARGC != 3) {
   print "You need 2 arguments on the command line"
   exit 13

$ ./Test
You need 2 arguments on the command line
$ echo $?
$ ./Test 1
You need 2 arguments on the command line
$ echo $?
$ ./Test 1 2
$ echo $?

# 5  
Old 12-05-2009
Thanks.That works.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script to match string and print status

Dear team, Need support to built awk script for below requirement Input file LOTC cluster state: ------------------- Node safNode=SC_2_1 joined cluster | Node safNode=SC_2_2 joined cluster | Node safNode=PL_2_3 fail cluster | AMF cluster state: ------------------... (16 Replies)
Discussion started by: shanul karim
16 Replies

2. Shell Programming and Scripting

Want to get the exit status

Hi All, I am trying to create a zip file with all the txt files(these are in large number) in the current directory. I am able to do this operation sucessfully. After this i want to get the status of the tar command executed and do accordingly. When i am trying with the below code, the status... (3 Replies)
Discussion started by: paddu
3 Replies

3. Shell Programming and Scripting

awk with exit status if pattern not found

Hi everyone, Looking at writing another awk program here to find a pattern on a text file. If patterns aren't found I want the awk program to exit and then bash to file a failure log on the local machine. Then later a management framework we have in place will read if that failure log file... (3 Replies)
Discussion started by: Zaphod_B
3 Replies

4. Shell Programming and Scripting

Exit Status

I have a shell script (#!/bin/sh) that interacts with Appworx and Banner Admin. In my script I want to check the exit status of awrun before continuing. awrun can run for 10 seconds or it can run for over a minute. So my question is, will it go through my if statement before awrun may even be... (2 Replies)
Discussion started by: smkremer
2 Replies

5. UNIX for Dummies Questions & Answers

Processes and exit status

Hi, I can't understand why the last $? is 1? can somebody plz help me to understand it? thanks $ ksh $ ps -f UID PID PPID C STIME TTY TIME COMMAND msarabad 12361 12319 0 15:17:58 pts/1 0:00 ksh msarabad 12319 12317 0 15:15:11 pts/1 0:00 -sh msarabad 12362 12361 ... (7 Replies)
Discussion started by: messi777
7 Replies

6. UNIX for Dummies Questions & Answers

service exit status

what are the number for the exit status for command service and what does every number mean. (2 Replies)
Discussion started by: programAngel
2 Replies

7. Shell Programming and Scripting

Exit status

I'm preparing for exam and one of exams is to write own test command... I wonder if in unix is a command which just returns exit code you specify.. I know I can easily write a function like this: exStatus() { return $1 } -> my question is rather theoretical thank you! (9 Replies)
Discussion started by: MartyIX
9 Replies

8. Shell Programming and Scripting

How to get the exit status

Hi all, I'm running a program which return 1 upon success. But when encounters problem shell return 's '1' . How to differentiate between them the shell return value and script return value. Ex. function fn return '1' if executed successfully and '0' if failed. But when if shell encounters... (1 Reply)
Discussion started by: yhacks
1 Replies

9. UNIX for Dummies Questions & Answers

how to check exit status in awk script

Hi, I have a main program which have below lines - awk -f test.awk inputFileName - I wonder how to check status return from awk script. content of awk script: test.awk --- if ( pass validation ) { exit 1 } else { (1 Reply)
Discussion started by: epall
1 Replies

10. Shell Programming and Scripting

exit status

i downloaded a text file from called sh.txt and in this reference manual it refers to shell scripting exit status .. at the end of one of the examples that author gave an exit status of 127.. to what does a 127 exit status refer too and what is its purpose in the code. moxxx68 (1 Reply)
Discussion started by: moxxx68
1 Replies
Login or Register to Ask a Question

Featured Tech Videos