09-21-2008
single line if statement
hi, i wonder if someone could tell me how to properly convert the following code onto one line:
if [ ! -f ./some_file ]
then
print "The file was not copied"
exit 1
fi
i am not sure how to close off the if statement here. everything i try gives me "syntax error: `if' unmatched"
if [ ! -f ./some_file ] && print "The file was not copied." && exit 1
thanks for your help.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
meas is a shell variable, and this works perfectly fine for me:
awk -v var=$meas -F, '$1==var' /abcd/efgh.txt > temp1.csv
However, i want to introduce another shell variable, named, defnfile in the statement, in place of hardcoded path for efgh.txt like:
awk -v var=$meas -F, '$1==var'... (3 Replies)
Discussion started by: indianjassi
3 Replies
2. Shell Programming and Scripting
Hi,
I have written a code to modify a string say,
StringA=abc,def,ghi
I need to change it to something like:
StringB=This means abc='ABC', This mean def='DEF', This means ghi= 'GHI'
StringB=$(echo $StringA | awk -F',' 'BEGIN { OFS="," } { for (i=1; i<=NF;i++) $i="This means... (2 Replies)
Discussion started by: tostay2003
2 Replies
3. Shell Programming and Scripting
Hi All,
I am trying to alter all lines between EXEC SQL and END-EXEC that have an INCLUDE in them.
The following code
search="INCLUDE "
cp -f ${WORK}/$file.in ${WORK}/$file.wrk2
for item in `echo $search `; do
> ${WORK}/$file.wrk1
awk -vITEM="$item" '{
if ( $0... (3 Replies)
Discussion started by: Bruble
3 Replies
4. Shell Programming and Scripting
Hi,
I have a requirement with,
No~Dt~Notes
1~2011/08/1~"aaa
bbb
ccc
ddd
eee
fff
ggg
hhh"
Single column alone got splitted into multiple lines.
I require the output as
No~Dt~Notes
1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh"
mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies
5. Shell Programming and Scripting
I am trying to test two conditions in a single if and getting syntax error on -a and &&
if ] ; then
echo "variable a equals to variable b"
else
echo "variable a not equal to variable b"
fi
in second attempt I used -a instead of &&, referring to other website, but not sure that... (1 Reply)
Discussion started by: praxis1
1 Replies
6. Shell Programming and Scripting
Good morning,
My first time actually posting in this forum, though I have used this forum to help with numerous projects.
I am trying to figure out why my if statement does not work. I have a file where a line is inputted every 15 seconds. I want this if statement to check what the last line... (3 Replies)
Discussion started by: Shanrunt
3 Replies
7. Shell Programming and Scripting
hi,
i am using ftp command to get some files from a remote server.
if the remote server contains files of different extension.
abc.txt
def.txt
ghi.lst
jkl.cnf
is it possible to get all the three type of files in one ftp?
i am using this ftp command
$FTP $Remote_server <<_FTP1
... (4 Replies)
Discussion started by: Little
4 Replies
8. Programming
A sample.c file is written with only one single statement.
main;
Segmentation fault occurred when executed that file.
Any statement other than main; is written, for example unix; then it won't compile.
why is this behaviour ! (2 Replies)
Discussion started by: techmonk
2 Replies
9. Shell Programming and Scripting
Hi,
Can we use 3 statements convert in a single statement.
First statement output using the second statement and the second statement output using the third statement please let me know the syntax so that I can able to merge all the three statement. (2 Replies)
Discussion started by: Priti2277
2 Replies
10. Shell Programming and Scripting
Hi,
Need help, using awk command to insert statement
awk -v q="'" '{ print "db2 connect to repolab > /dev/null; " "\n" "db2 -x \" select name from IBMPDQ.PROFILE where managed_database = " q $1"_"$3"__0" q "\"" } ' profile.txt | sh - | awk -v i="'" ' { print "db2 connect to repolab >... (1 Reply)
Discussion started by: Mathew_paul
1 Replies
PDO.EXEC(3) 1 PDO.EXEC(3)
PDO
::exec - Execute an SQL statement and return the number of affected rows
SYNOPSIS
public int PDO::exec (string $statement)
DESCRIPTION
PDO.exec(3) executes an SQL statement in a single function call, returning the number of rows affected by the statement.
PDO.exec(3) does not return results from a SELECT statement. For a SELECT statement that you only need to issue once during your program,
consider issuing PDO.query(3). For a statement that you need to issue multiple times, prepare a PDOStatement object with PDO.prepare(3) and
issue the statement with PDOStatement.execute(3).
PARAMETERS
o $statement
- The SQL statement to prepare and execute. Data inside the query should be properly escaped.
RETURN VALUES
PDO.exec(3) returns the number of rows that were modified or deleted by the SQL statement you issued. If no rows were affected, PDO.exec(3)
returns 0.
Warning
This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on
Booleans for more information. Use the === operator for testing the return value of this function.
The following example incorrectly relies on the return value of PDO.exec(3), wherein a statement that affected 0 rows results in a call to
die(3):
<?php
$db->exec() or die(print_r($db->errorInfo(), true));
?>
EXAMPLES
Example #1
Issuing a DELETE statement
Count the number of rows deleted by a DELETE statement with no WHERE clause.
<?php
$dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2');
/* Delete all rows from the FRUIT table */
$count = $dbh->exec("DELETE FROM fruit WHERE colour = 'red'");
/* Return number of rows that were deleted */
print("Deleted $count rows.
");
?>
The above example will output:
Deleted 1 rows.
SEE ALSO
PDO.prepare(3), PDO.query(3), PDOStatement.execute(3).
PHP Documentation Group PDO.EXEC(3)