05-25-2004
Passing the command line argument in a variable
Hi,
I am new to unix. Is their a way to pass the output of the line below to a variable var1.
ls -1t | head -1.
I am trying something like var1=ls -1t | head -1, but I get error.
Situation is: I get file everyday through FTP in my unix box. I have to write a script that picks up first latest file that comes in and pass the content of that file to another file called the load.txt. The FTP filename changes depending on the source.
I tried something like:
var1=ls -1t | head -1
cat $var1>load.txt
I error out on the first line of my script.
Also I tried something like var1=ls -1t | head -1 | cat >load.txt. But I am not getting the desired result.
I will really appreciate any help in this regards.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a shell script which does the encryption of a file where i am passing the file name as a command line argument,but later on the script waits on the screen to enter Y or N
what is the command i should be using on the shell script
#!/bin/bash -x
outfilename=file.out
echo... (8 Replies)
Discussion started by: rudoraj
8 Replies
2. Programming
The following program takes two command line arguments.
I want the second argument (fileCount) to be stored/printed as a int value. I tried my best to typecast the char to int (check the printf statement at last) but is not working...the output is some junk value.
This program is in its... (3 Replies)
Discussion started by: frozensmilz
3 Replies
3. Shell Programming and Scripting
$$$$$ (5 Replies)
Discussion started by: asirohi
5 Replies
4. UNIX for Dummies Questions & Answers
Hi,
I am facing a problem to pass command line arguments that looks like
<script name> aa bb "cc" dd "ee"
I want to pass all 5 elements include the " (brackets). when I print the @ARGV the " disappear. I hope I explain myself
Regards,
Ziv (4 Replies)
Discussion started by: zivsegal
4 Replies
5. Shell Programming and Scripting
Hi,
I had written a shell script to pass command line argument to variable in a function.
Here is my code:
main
if ; then
.$1
echo $1
get_input_file
else
echo "input file $1 is not available"
fi
get_input_file()
{
FILE = "$1"
echo $FILE
} (10 Replies)
Discussion started by: Poonamol
10 Replies
6. Shell Programming and Scripting
I have one working awk command line. Which taking data from the “J1202523.TXT” file and generating the “brazil.dat” file. PFB code.
awk '{ DUNS = substr($0,0,9);if ( substr($0,14,3) == "089" ) print DUNS }' J1202523.TXT > Brazil.dat
But now I want to pass two parameter as a command line argument... (4 Replies)
Discussion started by: humaemo
4 Replies
7. UNIX for Advanced & Expert Users
Hi,
In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles".
This is my code :
... (0 Replies)
Discussion started by: KidD312
0 Replies
8. Shell Programming and Scripting
Hello All,
I have a Bash Script and an Expect script that together will SSH to another server and
do some stuff there... From within the Bash Script I process the Command Line Arguments,
which are Required Args and Optional Args.
When I call the Expect script from the Bash Script, I pass... (4 Replies)
Discussion started by: mrm5102
4 Replies
9. Shell Programming and Scripting
Hi,
I am calling a Perl script in my shell script. When Perl script is executed it asks for a answer to be entered by user from terminal. How can i pass that value from my shell script ??
I know I can change perl script to default the answer but i dont have access to do that so only option i... (5 Replies)
Discussion started by: varun22486
5 Replies
10. Shell Programming and Scripting
Hi,
I am trying to pass a variable as an argument to another script. While substitution of variable, I am facing a problem.
varaiable "a" value should be -b "FPT MAIN".
When we pass "a" to another script, we are expecing it to get substitue as ./test.sh -b "FPT MAIN". But, it is getting... (9 Replies)
Discussion started by: Manasa Pradeep
9 Replies
LEARN ABOUT PHP
mysqli_stmt.bind_result
MYSQLI_STMT.BIND_RESULT(3) 1 MYSQLI_STMT.BIND_RESULT(3)
mysqli_stmt::bind_result - Binds variables to a prepared statement for result storage
Object oriented style
SYNOPSIS
bool mysqli_stmt::bind_result (mixed &$var1, [mixed &$...])
DESCRIPTION
Procedural style
bool mysqli_stmt_bind_result (mysqli_stmt $stmt, mixed &$var1, [mixed &$...])
Binds columns in the result set to variables.
When mysqli_stmt_fetch(3) is called to fetch data, the MySQL client/server protocol places the data for the bound columns into the speci-
fied variables $var1, ....
Note
Note that all columns must be bound after mysqli_stmt_execute(3) and prior to calling mysqli_stmt_fetch(3). Depending on column
types bound variables can silently change to the corresponding PHP type.
A column can be bound or rebound at any time, even after a result set has been partially retrieved. The new binding takes effect
the next time mysqli_stmt_fetch(3) is called.
PARAMETERS
o $
stmt -Procedural style only: A statement identifier returned by mysqli_stmt_init(3).
o $var1
- The variable to be bound.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
EXAMPLES
Example #1
Object oriented style
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
/* prepare statement */
if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
$stmt->execute();
/* bind variables to prepared statement */
$stmt->bind_result($col1, $col2);
/* fetch values */
while ($stmt->fetch()) {
printf("%s %s
", $col1, $col2);
}
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>
Example #2
Procedural style
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (!$link) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
/* prepare statement */
if ($stmt = mysqli_prepare($link, "SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
mysqli_stmt_execute($stmt);
/* bind variables to prepared statement */
mysqli_stmt_bind_result($stmt, $col1, $col2);
/* fetch values */
while (mysqli_stmt_fetch($stmt)) {
printf("%s %s
", $col1, $col2);
}
/* close statement */
mysqli_stmt_close($stmt);
}
/* close connection */
mysqli_close($link);
?>
The above examples will output:
AFG Afghanistan
ALB Albania
DZA Algeria
ASM American Samoa
AND Andorra
SEE ALSO
mysqli_stmt_get_result(3), mysqli_stmt_bind_param(3), mysqli_stmt_execute(3), mysqli_stmt_fetch(3), mysqli_prepare(3), mysqli_stmt_pre-
pare(3), mysqli_stmt_init(3), mysqli_stmt_errno(3), mysqli_stmt_error(3).
PHP Documentation Group MYSQLI_STMT.BIND_RESULT(3)