Sponsored Content
Top Forums Shell Programming and Scripting IF statement with square brackets Post 302983624 by Don Cragun on Friday 14th of October 2016 03:21:22 AM
Old 10-14-2016
The real question is not what the region is when the code works or fails, but to what do the expansions of the three shell variables: com_dir, dup_file_name_chk, and save_dir expand when the code works and to what do they expand when it fails. One might guess that it is failing when one of those variables contain one or more whitespace characters. One might also guess that the following would also work:
Code:
if [ -f "$com_dir/$dup_file_name_chk" ] || 
[ -f "$save_dir/$dup_file_name_chk" ]
then
.
.
.
fi

You haven't told us what shell you're using, but if [[ expression ]] is working and you're running on AIX, I'll assume you are using ksh or bash. The command:
Code:
[ -f $com_dir/$dup_file_name_chk ]

is a shell built-in utility that performs the same parameter expansion and field splitting that happens whenever the shell evaluates a command line. Without the double quotes surrounding the parameter expansions, if there are whitespace characters in the expansions of those variables, field splitting will cause one or both of those tests to fail. It will also fail if $dup_file_name_chk expands to an empty string. but in that case the double bracket test would also fail.

The command:
Code:
[[ -f $com_dir/$dup_file_name_chk ]]

is part of the syntax of the shell; not a utility. Parameter expansion still occurs in this case, but field splitting does not occur.
These 2 Users Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

square brackets

I would like to substitute a phrase which contains square brackets. change TO how? Thanks (2 Replies)
Discussion started by: gilead29
2 Replies

2. Shell Programming and Scripting

WHy the double square brackets?

One of the senior administrators gave me a shell script to modify and it begins as follows: if ] && ] {more code follows} Why the double square brackets? (10 Replies)
Discussion started by: mojoman
10 Replies

3. Shell Programming and Scripting

Double square brackets question

Hi, I just came across an interesting shell script syntax like the one below: ] && (trap 'rm -rf ${WORK_DIR}/*.$$; echo "\n\nInterrupted !!\n\n"; exit 4' 1 2 3 15) Can someone please explain the code snippet above? The trap command bit is fine but ] && is the hazy part. Generally we use an... (2 Replies)
Discussion started by: King Nothing
2 Replies

4. UNIX for Dummies Questions & Answers

Test command - Two square brackets

Hello, Can someone please explain to me the following line, ] && break I do not understand why two test square brackets are used. Thanks, Shantanu ---------- Post updated at 03:38 PM ---------- Previous update was at 03:35 PM ---------- And, also why there's a $ before (echo $c |... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

5. Shell Programming and Scripting

Replacing text between two square brackets

hi guys, i'm writing a script that looks for a unquie id in a file and replaces a string between two square brackets on the same line as the unquie id: ....... ....... 0001 zz 43242 replace this text] name 0002 sd 65466 UK] country ....... ....... how can i find line with id 0001... (6 Replies)
Discussion started by: zaff
6 Replies

6. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

7. Shell Programming and Scripting

Extract text between two square [..] brackets

Hi All, After searching about this, I could find some solutions but I am not sure why it is not working in my case. I have a text file with contents between two square brackets. The text file looks like this: Use tags when you post any code so others can easily read your code. You can... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

8. UNIX for Dummies Questions & Answers

Single or double square brackets

Hi frieds, I don't understand the difference between single square bracket and double square brackets in a IF condition. Ex. if ; then RETURNJOB=1 else RETURNJOB=0 fi It run, but this if ]; then RETURNJOB=1 else RETURNJOB=0 fi (4 Replies)
Discussion started by: dogshort
4 Replies

9. Shell Programming and Scripting

Grep number between Square [] brackets

I wanted to store the number inside the square bracket between colon( : ) and closing suqre bracket(]) in some variable. Suppose I have lines like : Input file : 20140320 00:08:23.846 INFO 84] - anything in line 20140320 00:08:23.846 Test 589] - Virtual and lab lab anything... (18 Replies)
Discussion started by: nes
18 Replies

10. Shell Programming and Scripting

Problem with occurence of square brackets

Hello all, I have the following problem: $ cat infile this is spam and i need this too this is spam and i need this too $ perl -nwe '$_ =~ /]+ \]+)\]\]*\]? (\+)$/; print "$1 - $2\n";' infile i need this - too i need this - and i need this too I am not sure how many occurences of... (13 Replies)
Discussion started by: zaxxon
13 Replies
QPaintEvent(3qt)														  QPaintEvent(3qt)

NAME
QPaintEvent - Event parameters for paint events SYNOPSIS
#include <qevent.h> Inherits QEvent. Public Members QPaintEvent ( const QRegion & paintRegion, bool erased = TRUE ) QPaintEvent ( const QRect & paintRect, bool erased = TRUE ) const QRect & rect () const const QRegion & region () const bool erased () const DESCRIPTION
The QPaintEvent class contains event parameters for paint events. Paint events are sent to widgets that need to update themselves, for instance when part of a widget is exposed because a covering widget is moved. The event contains a region() that needs to be updated, and a rect() that is the bounding rectangle of that region. Both are provided because many widgets can't make much use of region(), and rect() can be much faster than region().boundingRect(). Painting is clipped to region() during processing of a paint event. The erased() function returns TRUE if the region() has been cleared to the widget's background (see QWidget::backgroundMode()), and FALSE if the region's contents are arbitrary. See also QPainter, QWidget::update(), QWidget::repaint(), QWidget::paintEvent(), QWidget::backgroundMode, QRegion, and Event Classes. MEMBER FUNCTION DOCUMENTATION
QPaintEvent::QPaintEvent ( const QRegion & paintRegion, bool erased = TRUE ) Constructs a paint event object with the region that should be updated. The region is given by paintRegion. If erased is TRUE the region will be cleared before repainting. QPaintEvent::QPaintEvent ( const QRect & paintRect, bool erased = TRUE ) Constructs a paint event object with the rectangle that should be updated. The region is given by paintRect. If erased is TRUE the region will be cleared before repainting. bool QPaintEvent::erased () const Returns TRUE if the paint event region (or rectangle) has been erased with the widget's background; otherwise returns FALSE. const QRect &; QPaintEvent::rect () const Returns the rectangle that should be updated. See also region() and QPainter::setClipRect(). Examples: const QRegion &; QPaintEvent::region () const Returns the region that should be updated. See also rect() and QPainter::setClipRegion(). Examples: SEE ALSO
http://doc.trolltech.com/qpaintevent.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qpaintevent.3qt) and the Qt version (3.1.1). Trolltech AS 9 December 2002 QPaintEvent(3qt)
All times are GMT -4. The time now is 08:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy