Sponsored Content
Top Forums Shell Programming and Scripting [bash] Executing script that is held in a variable Post 302387554 by ASGR on Sunday 17th of January 2010 06:55:31 AM
Old 01-17-2010
Fantastic.

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:
Code:
#!/bin/bash
ARRAY[0]='#!/usr/bin/python'
ARRAY[1]='print "Hello, Python!"'

IFS="
 "

script="$(echo "${ARRAY[*]}")"
eval "${ARRAY[0]#\#!}" <(printf "$script")

and
Code:
#!/bin/bash
ARRAY[0]='#!/usr/bin/perl -w'
ARRAY[1]='use strict;'
ARRAY[2]='print "Hello, Perl!\n";'

IFS="
 "

script="$(echo "${ARRAY[*]}")"
eval "${ARRAY[0]#\#!}" <(printf "$script")



---------- 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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding out the length of a string held within a variable

:confused: Does anyone know which command I can use to find out the length of a string held within a variable? (5 Replies)
Discussion started by: dbrundrett
5 Replies

2. Shell Programming and Scripting

Trying to create variable, value not being held

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)
Discussion started by: cstovall
2 Replies

3. Shell Programming and Scripting

How do you parse a variable in a bash script?

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)
Discussion started by: vertical98
3 Replies

4. Shell Programming and Scripting

passing variable from bash to perl from bash script

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)
Discussion started by: arsidh
10 Replies

5. Shell Programming and Scripting

variable issue in a bash in a shell script

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)
Discussion started by: bioBob
2 Replies

6. Shell Programming and Scripting

Bash script errors when executing

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)
Discussion started by: rayne127
2 Replies

7. UNIX for Dummies Questions & Answers

Write pid and command name to a txt file while executing a bash script

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)
Discussion started by: rahulkalra9
2 Replies

8. Shell Programming and Scripting

Acces Variable from expect-Script in bash-Script

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)
Discussion started by: gandalfthepink
3 Replies

9. Shell Programming and Scripting

Bash script if condition not executing

issue is with .txt files (7 Replies)
Discussion started by: anil529
7 Replies

10. Shell Programming and Scripting

Executing sed command inside a bash script

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)
Discussion started by: Kangol
3 Replies
All times are GMT -4. The time now is 05:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy