01-08-2016
How to pass each line of a text file as an argument to a command?
I'm looking to write a script that takes a .txt filename as an argument, reads the file line by line, and passes each line to a command. For example, it runs command --option "LINE 1", then command --option "LINE 2", etc. I am fetching object files from a library file, I have all the object file names saved in .txt file.
How do I go about doing that? Just a Single Line of Command with different filenames from text file.
I don't know where to start.
I am using MAC terminal.
Thanks in advance.
Paul
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi ,
I have a piece of code ...wherein I need to assign the following ...
1) A command line argument to a variable
e.g origCount=ARGV
2) A unix command to a variable
e.g result=`wc -l testFile.txt`
in my awk shell script
When I do this :
print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies
2. 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
3. Shell Programming and Scripting
How can I pass $var_find variable as argment to find command?
test.sh
var_find=' \( -name "*.xml" -o -name "*.jsp" \) '
echo "${var_find}"
find . -type f ${var_find} -print
# Below statement works fine.. I want to replace this with the above..
#find . \( -name "*.xml" -o -name... (4 Replies)
Discussion started by: kchinnam
4 Replies
4. UNIX for Dummies Questions & Answers
Hi all,
I have a large text file and also a smaller list of program names. I want to find out how many of those programs exist in the large text file. Can someone help me with the command/script please. The program list is along the lines of
tranwe2
tranwe3
tranye5
etc
so basically I... (5 Replies)
Discussion started by: Grueben
5 Replies
5. Shell Programming and Scripting
Hi,I have a script which is given below :#!/bin/bash. ini_script.shdb2 connect to $DB_NAME user $DB2_UID using $DB2_PASSWORDfor file in `ls -1 ./sql/ddw/`do echo "Executing the file $file" echo db2 -tvf $filedonedb2 quiti want this script to accept directorie's names present in... (1 Reply)
Discussion started by: ektubbe
1 Replies
6. Shell Programming and Scripting
Hi all,
How to pass the command line argument to a sql file
Script:
#!/bin/ksh
if ] ; then
test.sql
fi
My Sql Informix DB:
echo "select * from table where col1 = 2234
and col2 = '$3'"|dbaccess ddname
But im getting `:' unexpected error (5 Replies)
Discussion started by: Roozo
5 Replies
7. Shell Programming and Scripting
I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like
invalid option - - should pass the argument.
and Exit from the script
https://www.unix.com/images/misc/progress.gif (1 Reply)
Discussion started by: Nsharma3006
1 Replies
8. UNIX for Dummies Questions & Answers
I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like
invalid option - - should pass the argument.
and Exit from the script (8 Replies)
Discussion started by: Nsharma3006
8 Replies
9. Shell Programming and Scripting
Hi,
Is there any way that we can pass one file as one of the argument in shell script ? (1 Reply)
Discussion started by: Selva_2507
1 Replies
10. Shell Programming and Scripting
Hello
Does the unix korn shell provide a function to convert number entered in command line argument to text or Character so that in next step i will convert Chr to Hex (6 Replies)
Discussion started by: aadityapatel198
6 Replies
LEARN ABOUT DEBIAN
test::assertions::testscript
Test::Assertions::TestScript(3pm) User Contributed Perl Documentation Test::Assertions::TestScript(3pm)
NAME
Test::Assertions::TestScript - Base for test scripts
SYNOPSIS
use Test::Assertions::TestScript;
use Module::To::Test qw( frobnicate );
ASSERT(frobnicate(),"Frobnicate returns true");
DESCRIPTION
Test::Assertions::TestScript provides a base for writing test scripts. It performs some common actions such as setting up the @INC path and
parsing command-line options, specifically:
o The lib and t/lib directories are added to @INC.
o The current directory is changed to the directory the script is in.
o Test script command-line options are parsed. (See "COMMAND-LINE OPTIONS")
o The test set of functions from Test::Assertions are imported into your test script.
Test::Assertions::TestScript makes certain assumptions about the filesystem layout of your project:
o Modules that you are testing are in the lib directory of your project.
o Test scripts are in the t directory.
o There may also be a t/lib directory for any modules written for the test process.
Test::Assertions::TestScript should be "use"d before any modules that you intend to test.
OPTIONS
Options can be supplied to the import function. These should be placed after the "use" or "import". For example
use Test::Assertions::TestScript( tests => 10, options => { 'b', $opt_b })
The following options are defined:
tests
The number of tests to pass to "plan tests" from Test::Assertions. For example to tell Test::Assertions::TestScript that the script
contains 42 tests:
use Test::Assertions::TestScript tests => 42;
options
A hashref of additional options to capture via Getopt::Long. The "options" import parameter is passed verbatim to GetOptions, so
something along the following lines is required in order to capture the "-b" command line option:
use Test::Assertions::TestScript( options => { 'b' => $opt_b } );
COMMAND-LINE OPTIONS
A script based on Test::Assertions::TestScript will detect the following command line options.
-t Shallow tracing. Traces are "print"ed and AutoImport is turned on.
-T Deep tracing. Traces are "print"ed and AutoImport is turned on.
--trace-module=MODULE
Imports tracing into MODULE specifically. Can be specified multiple times.
-s Save generated output. You will need to write the actual code to do this in your testscript, but you can inspect
$Test::Assertions::TestScript::SAVE_OUTPUT to see whether this argument was given.
Be aware that all other command line options will be disregarded unless the "options" import parameter is used to capture them.
VERSION
$Revision: 1.18 $
AUTHOR
Colin Robertson <cpan _at_ bbc _dot_ co _dot_ uk>
COPYRIGHT
(c) BBC 2005-6. This program is free software; you can redistribute it and/or modify it under the GNU GPL.
See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt
perl v5.10.0 2006-08-10 Test::Assertions::TestScript(3pm)