First of all, you should use single quotes when assigning to the array variables or escape the inner double quotes. Also, you are intermingling ARRAY and array.
Try:
To use other interpreters than bash you have to somehow invoke those interpreters. One way would be to use the contents of the shebang:
-or-
Last edited by Scrutinizer; 01-16-2010 at 12:25 PM..
Should have seen the intermingling but I was working from
several examples and ended up copy/pasting from several
scripts.
Thanks to both jlliagre and Scrutinizer for all your help.
For future reference, these scripts work:
and
---------- Post updated at 07:55 AM ---------- Previous update was at 06:21 AM ----------
Just a small problem.
The function that loads and assigns the array that contains the
script seems to imply double quotes. Is their a quick method
that could be built into a function to convert each element of
an array from double quotes to single quotes. Or if possible, to
include it within the eval statement.
I tried putting single quote escape characters around ARRAY
but that didn't seem to work.
A.
Last edited by ASGR; 01-17-2010 at 08:01 AM..
Reason: update
This is an extract from the project,
And this is an example of a data file that would contain tags including
scripts as well as others. The location of which has to be specified in
the variable above.
The sections don't have a corresponding closing tag. They are terminated
with either another tag or end of file, handled by the 'for' loop in the
'tag_filters' function. It was designed to take wildcards so that similar
tags would be filtered and then the contents of the array could be
refined and/or appended to each other with another function.
Conveniently, it also takes absolutes.
Getting back to the problem... I'm still experiencing problems with
incomplete commands, due to the lack of single quotes around the
elements of the array. The whole process is programatically applied
and I have no opportunity to manually insert single quotes around the
elements of the array.
To solve the problem, I was wondering if it was possible to somehow
incorporate the single quote solution into the 'array_script' command
so that whenever a script is invoked, it is processed there.
Alternatively, an acceptable solution would be a function that converts
an array so that each element is surround by single quotes just before
the 'array_script' function is called.
Hi ASGR, you could give this a try:
I removed the :1 and added the escape inner double quotes.
---
I think the script you provided is perhaps a tad difficult to read. I am not convinced arrays are the way to go since IMO plain variables will serve that same purpose just fine. Also I am not sure if the abundant use of functions together with call by name paramter passing through the eval mechanism adds much to the clarity of the script.
---
FWIW, based on your latest input file specifications I created the following example script for you to use as a comparison:
Output:
And here is the same script using a plain function with global variables and no parameters passing:
S.
Just to explain the method behind the madness, I'm trying
to create a reusable library of functions that is majority
array related.
Whilst consulting with a fellow forum user, it was determined
that using 'eval' was the best, if not only, solution to assign
and return arrays from functions. From there-on everything
became eval based for the sake of consistency.
The consequence of using bash and arrays with functions is the use of name passing through eval. I think that you can probably also build those functions on the basis of plain variables and the read shell builtin. I think it is just a matter of preference. The use of variables is merely an alternative approach that may lead to simpler code..
Last edited by Scrutinizer; 01-18-2010 at 03:52 AM..
I want to run commands inside a bash script.
An example is
I want to pass the command in a string as regexp as an argument to the script, then run sed on the bash variable
sed.sh regexp
sed.sh "-i \"s/<p>//g\""
then call
sed "$regexp" $fl (3 Replies)
Hi all,
I have a little problem with a expect in a bash Script.
The hull of my script:
#!/bin/sh
( expect -c '
set a \"eee\"; # the variable a
' )
echo $a; # using the variable out of the expect script
I would like to use the variable out of the expect script(in bash),... (3 Replies)
Hi All,
Just have a requirement, I am executing a bash shell script, my requirement is to catch the pid and job name to a txt file in the same directory, is there anyway to do it? please help me out.
Regards
Rahul
---------- Post updated at 08:42 AM ---------- Previous update was at... (2 Replies)
I'm working on a script that will search through a directory for MKV files and remux them to MP4. I found a few other scripts around the net that do this, but they all have limitations that don't always get the job done. The main limitation I've found is that most scripts look for the video track... (2 Replies)
Hi,
I am trying to write a PBS shell script that launches a bash process. The issue is that the bash process needs a variable in it and the shell script is interpreting the variable. How do I pass this as a literal string? Here is my code snippit:
TMP=".fasta"
FILEOUT=$FILE$TMP
cd... (2 Replies)
Hi All,
I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl
FROM_DATE="06/05/2008"
TO_DATE="07/05/2008"
"perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename"
filename has... (10 Replies)
I have a script I use on my web server (Apache2). I am changing to Lighttpd and need to make a few changes.
This is what I use on my apache server
#!/bin/bash
# accepts 3 parameters: <domain name> <user name> <XXXXXXXX>
# domain name is without www (just domain.com)
# username would be... (3 Replies)
I tried creating a variable with the awk command. The correct value is being printed to the screen; however, the variable max is not being set. The command "echo $max" is null. Any help would be greatly appreciated. Thank you.
cat test.txt:
-rw-r--r-- 1 root root 0 2005-01-12 20:51... (2 Replies)