Hi,
I want a command in unix shell script which will exit my whole program, not only from the function it's using. For e.g:
$1 == "m_who" && $4 == "Extrnl Vendor" {
print "You don have access"
exit \(0\);
}
If this error is showing on the screen, then nothing should not proceed further. I want this program to stop here instead of going forward for next function or steps. Finally, I want this error on the screen.
I have tried the 'break' command too, but did not get any proper result.
Any command apart from exit and break, we can use ? Hope I am clear with my doubt.
Please clarify what language (or, more likely, languages) you are using here. If you have a shell script that is invoking awk, you need to realize that awk is a child process. The parent process must decide when it wants to exit. Assuming ksh invoking an awk script, you could do something like:
if awk '{ ... }' ; then exit 0; fi
And in the awk script, use either:
exit(1) to get out of awk and cause the script to exit
exit(0) to get out of awk but allow the shell script to continue.
Reread my post. I said to do:
if awk '{ ... }' ; then exit 0; fi
Somehow the shell script must test that exit code from awk and then decide to exit. The script you show is ignoring the exit code from awk.
Could you please update the code and let me know ? I was trying with both exit (0) and exit (1), but still getting the same result. I do not know whether doing in the same way, you want me or not. So, Please modify my sample code in the way you want to explain me.
Is it possible to use if condition along with the executable file inside an awk program ? For e.g.
if ( ($1 == "m_who") && ($4 == "External")) {
print "You don have access"
exit(0)
};
else{
system("./exbin/mk_ht ./high/practice.ihtml")
}
Look at it this way... "true" does an "exit(0)" while "false" does an "exit(1)". Now consider this script:
$ cat one
#! /usr/bin/ksh
echo one
true
echo two
false
echo three
exit 0
$ ./one
one
two
three
$
Those exit codes did nothing to stop the script from running. This is because the script is ignoring the exit codes. To fix that, I must change the script to test the exit codes:
$ cat two
#! /usr/bin/ksh
echo one
if true ; then exit 0 ; fi
echo two
if false ; then exit 0 ; fi
echo three
exit 0
$ ./two
one
$
Now because I tested the exit codes, that exit code from "true" stopped the script from finishing. You have a nawk script embedded in a shell script. You must change you outer shell script to test the exit code from nawk. I don't have gu or mk_ht on my box (never even heard of them before) and I don't know what shell you're using so I cannot fix your code snippet.
Yes, Thanks for such a nice reply. But, thing is that this is not working along with HTML code. Where I need to include both HTML and nawk code.
The command exit (0) is existing from the nawk function, but it's executing the next line, i.e. "./exbin/mk_ht ./high/practice.ihtml".
Is it possible to use if condition along with the executable file inside an awk program ? For e.g.
if ( ($1 == "m_who") && ($4 == "External")) {
print "You don have access"
exit(0)
};
else{
system("./exbin/mk_ht ./high/practice.ihtml")
}
As it's in a HTML code, the SYSTEM call is also not working properly.
I want to avoid to do anymore operation after the error message. Please let me know if you have any clue regarding this.
What HTML code are you talking about? You cannot execute awk scripts within HTML code (HTML is not a programming language), unless you are using SSI CGI scripts, in which case, where is awk getting its input?
This code is for front end, which is using HTML and java script. This is one of the program, which was using nawk and working fine. I have given the sample code also. I need to add one more condition as to exit the whole program once the error will prompt.
Once we get the error, it should come out of the program or stop there itself instead of coming ONLY out of that loop.
Hope it's clear enough now. The sample code is also posted in my earlier reply.