tests if a string is NULL. The quotes are important -- without them a null string becomes [ -z ] which is a syntax error.
Same below, you need to quote things.
Note the single-quotes inside double-quotes around sftp_destination. That keeps it in single quotes even when sent to the remote server.
For the sake of argument, the ksh built=in test "[[" handles a null variable. At least on our Sun box. Consider this:
Output:
Of course if you explicitly need to test for null by itself, by all means use '-z' (or '-n' for not null) as testing like this is really testing for 3 conditions at once and may not be the desired action.
tests if a string is NULL. The quotes are important -- without them a null string becomes [ -z ] which is a syntax error.
Caution: Nitpick ahead.
That may be true of older implementations of test/[, but, for contemporary implementations, while the recommendation is sound, the analysis is incorrect.
A POSIX-compliant test/[, when passed a single argument, will succeed if the argument is not null, regardless of the value of that argument (i.e. it will never interpret the string as an operator of any kind).
When $STRING is null, [ -z $STRING ] reduces to a single, non-null argument, -z, and will always return true. There is no syntax error and the correct exit status is achieved through an unintended mechanism.
If $STRING is non-null and does not contain any IFS characters, again the correct exit status is returned.
The only problematic scenario occurs when the result of $STRING is split into multiple arguments, and this is why the quoting is sound advice.
Regards,
Alister
---------- Post updated at 12:16 PM ---------- Previous update was at 12:06 PM ----------
As a result of POSIX prescribing that test interpret its arguments in different ways depending on their number, we no longer have to resort to inelegant hacks to protect parameter expansion against collisions with test's operators. We can safely write
instead of
which is often seen in older sh scripts (and in some newer ones as well).
Hi folks,
I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex.
I have a bunch of update statements with all columns in a file which I need to convert into insert statements.
UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
I apologize if this question has been answered else where or is too elementary.
I ran across a KSH script (long unimportant story) that does this:
if ; then
CAS_SRC_LOG="/var/log/cas_src.log 2>&1"
else
CAS_SRC_LOG="/dev/null 2>&1"
fithen does this:
/usr/bin/echo "heartbeat:... (5 Replies)
How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&"
echo "hello" > /dev/null 2>&1
echo "hello" > /dev/null 2>1 (3 Replies)
I have an input file having 7 fields delimited by ,
eg :
1,ABC,hg,1,2,34,3
2,hj,YU,2,3,4,
3,JU,kl,4,5,7,
4,JK,KJ,3,56,4,5
The seventh field here in some lines is empty, whereas the other lines there is a value.
How do I insert string NULL at this location (7th loc) for these lines where... (8 Replies)
Hi,
How do you echo something once when a find statement returns null results?
This is when using mutiple locations and mutiple arguments.
The below find command the inner loop of a nested for loop where the outter loop holds the $args and the inner loop holds the locations.
find... (2 Replies)
Hi All,
I am using Unix ksh script.
I need to insert values to a table using the o/p from a slelect statement.
Can anybody Help!
My script looks like tihs.
---`sqlplus -s username/password@SID << EOF
set heading off
set feedback off
set pages 0
insert into ${TB_NAME}_D... (2 Replies)
In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands.
How do I write the "do nothing" statement in the following example?
Example:
if (( "$x"="1" && "$y"="a" && "$z"="happy" ))
then
do nothing
else
command
command
fi... (3 Replies)
I've got a very peculiar situation. I'm trying to find out if we can compare null fields with non-null. I've output csv files from SQL and Oracle. I need to compare each field from the files, and then find out any differences. The files usualy have over 500 fields, and send the resule to DBA.... (8 Replies)
Okay i've got some code which reads a text file and loops through it and there a few if statements inside where one is failing (the one bolded).
Basically the acc column contains a list of three digit access codes, some though have null records (i.e nothing in the field) so what I want to do is... (3 Replies)
Hello All,
I have a file of the format
****
123 abc ABC
456 bcd BCD
789 def
112 ghi GHI
223 jkl
344 mno MNO
****
I am trying to extract the lines that have no values in the third field (in this case, this would be
789 def
223 jkl
Can anyone please help??... (1 Reply)