08-30-2013
Quote:
Originally Posted by
jfxdavies
If I use the following:
[ $? != 0 ] && echo "echo failed"
$? returns 1
When I use
if [ $? != 0 ] ; then echo "echo failed" ; fi
$? returns 0
Does anyone know what's wrong with this?
There is nothing wrong. What you are seeing is correct behavior. In each case you are seeing the exit status of the last command to run.
In the first case, the last command before echoing $? is
[ $? != 0 ]. The test failed and so $? is set to 1.
In the second case, you're seeing the exit status of the if-statement itself. Since the conditional test fails, the if-statement does not execute further, the list of commands after
then does not execute. So the if-statement itself sets $? to 0.
That following quote is from
POSIX: Shell Command Language, but your KSH man page should contain similar text.
Quote:
The exit status of the if command shall be the exit status of the then or else compound-list that was executed, or zero, if none was executed.
Regards,
Alister
Last edited by alister; 08-30-2013 at 12:22 PM..
This User Gave Thanks to alister For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I'm having a question about for loops. (bash)
I have the following for example:
for file in `ls *.txt`
do
read file ...
done
Now when there is a file present there is no problem, now when there is no file present I get the following output in my standard mail box : "No such... (4 Replies)
Discussion started by: lumdev
4 Replies
2. UNIX for Dummies Questions & Answers
I'm guessing i have a syntax error. I'm not sure it get's past the the while condition. I get an error 0 not found. Simple loop not sure what I'm doing wrong.
#!/usr/bin/ksh
set -A MtPtArray /u03 /u06
tUbound=${#MtPtArray
}
echo $tUbound
i=0
while ($i -lt $tUbound)
do
print... (4 Replies)
Discussion started by: KME
4 Replies
3. UNIX for Dummies Questions & Answers
Hi All,
Thanks all of you for the help you provide to me. Well, I have one more problem, where I am trying to pull file system information in the loop and display the filesystem percentege. I am using following code to achive this, nut it's giving the weired output.
My file system is
... (1 Reply)
Discussion started by: alok.behria
1 Replies
4. UNIX for Dummies Questions & Answers
can some one please tell me what is the problem with my syntax:confused:
I have 100 files in one folder
1. want to read each of the line by line
2. calculate their number of the words between the first word and the last word of each line
3. create file for each file with number of words... (8 Replies)
Discussion started by: A-V
8 Replies
5. Shell Programming and Scripting
Hi
I've gotten a plugin script that won't run. I keeps throwing an error at the following line.
for BARCODE_LINE in `cat ${TSP_FILEPATH_BARCODE_TXT} | grep "^barcode"`
do
#something
done
The error reads
... (3 Replies)
Discussion started by: jdilts
3 Replies
6. Shell Programming and Scripting
Iam having a script which is used to load users and dumpfile in any given schema.Iam trying to autolog the script and have added two fucntion in it.
function init_stdout_redirect {
OUT_LOG=$1
OUT_PIPE=$(mktemp -u)
# Create the output pipe
mkfifo $OUT_PIPE
# Save stdout and... (15 Replies)
Discussion started by: Vikram_Tanwar12
15 Replies
7. Shell Programming and Scripting
I am getting the following error when I am running a script in ksh when trying to execute an if statement comparing two numerical values
tstmb.sh: 1.5321e+08: 0403-057 Syntax error
Below is my code snippet.
#!/bin/ksh
set -x
TODAY=$(date +%y%m%d)
for file in $(ls -rt *.log | tail... (11 Replies)
Discussion started by: kiran1112
11 Replies
8. Shell Programming and Scripting
Hi gurus,
I hit a block when write the script.
I need do while loop, in the loop I have code below.
sqlplus -s abc/abc@abc <<EOF
spool testwhile
select *
from dual;
spool off
exit;
EOF
when I run script with only this code, it works fine.
if I add code as below:
#!/bin/ksh
... (5 Replies)
Discussion started by: ken6503
5 Replies
9. Shell Programming and Scripting
I have the following code in bash, however "set red frmt" is not displayed.
echo "iarg_rd = $iarg_rd"
iarg_rd="2"
if ; then
echo "Hello World"
fi
if ; then
frmt="${gap}${!frmt_titl_yl}"
elif ; then
frmt="${gap}${!frmt_titl_bk}"
elif ; then
echo... (2 Replies)
Discussion started by: kristinu
2 Replies
10. Shell Programming and Scripting
hi all,
I created a sh script to import some tables from mysql to hive.
No problem launching it manually, but if I schedule via crontab it returns me an error in the following part:
#create an array containing all the tables for $dbname
query="SELECT table_name FROM information_schema.tables'... (10 Replies)
Discussion started by: mfran2002
10 Replies
LEARN ABOUT REDHAT
glcolormask
GLCOLORMASK(3G) GLCOLORMASK(3G)
NAME
glColorMask - enable and disable writing of frame buffer color components
C SPECIFICATION
void glColorMask( GLboolean red,
GLboolean green,
GLboolean blue,
GLboolean alpha )
PARAMETERS
red, green, blue, alpha
Specify whether red, green, blue, and alpha can or cannot be written into the frame buffer. The initial values are
all GL_TRUE, indicating that the color components can be written.
DESCRIPTION
glColorMask specifies whether the individual color components in the frame buffer can or cannot be written. If red is GL_FALSE, for exam-
ple, no change is made to the red component of any pixel in any of the color buffers, regardless of the drawing operation attempted.
Changes to individual bits of components cannot be controlled. Rather, changes are either enabled or disabled for entire color components.
ERRORS
GL_INVALID_OPERATION is generated if glColorMask is executed between the execution of glBegin and the corresponding execution of glEnd.
ASSOCIATED GETS
glGet with argument GL_COLOR_WRITEMASK
glGet with argument GL_RGBA_MODE
SEE ALSO
glClear(3G), glColor(3G), glColorPointer(3G), glDepthMask(3G), glIndex(3G), glIndexPointer(3G), glIndexMask(3G), glStencilMask(3G)
GLCOLORMASK(3G)