Executing the result of a program as a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing the result of a program as a shell script
# 1  
Old 11-04-2011
Executing the result of a program as a shell script

I have a program that returns a shell script and I want to execute the script.

I'll use cat in my simple example, but wget is an example that is feasible.

Code:
$ # First setup a script
$ echo "ls
> df" > simple
$ # "cat simple" is now a program that returns a script
$ cat simple
ls
df
$

Now I want to execute the script returned from "cat simple". I am sure that there must be a way to do it, probably using nothing more than punctuation, but I haven't found it.
Code:
$ # This method works, but is ugly and needs write access to somewhere
$ cat simple > /tmp/somefile
$ . /tmp/somefile
< output of ls and df >
$ rm /tmp/somefile
$ 
$ # I want to do something like this:
$ `cat simple`
ls: cannot access df: No such file or directory
$ # Only it doesn't work

Does anyone have an idea of how to do this without writing to a temporary file?
# 2  
Old 11-04-2011
Welcome to the forum .. Thanks for using code tags ..

To execute the simple file use some shell to run it ..
Code:
$ cat simple
ls
df
$ sh simple
< output of ls and df >
$

https://www.unix.com/shell-programmin...-terminal.html
# 3  
Old 11-04-2011
Thanks for the quick reply.

I don't want to run a file called simple. I only used "cat simple" as an example of a program which outputs a script. As I said wget might by a real-world application.

My application is actually a program that retrieves a script from the non-volatile RAM on a router!
# 4  
Old 11-04-2011
If 'I want to execute the script returned from "cat simple"' isn't what you want to do, then I'm not clear on what your question actually is?

EDIT: Do you mean something like:
Code:
 myscript="df;ls"; eval $myscript


Last edited by CarloM; 11-04-2011 at 07:38 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing the shell script through java program

Hi Team, Can you pls advise in java how can we call a shell script, actly I have a shell script at the following location /opt/dd/ajh.sh now I can execute this script by opening the session through putty by entering the servers details and password and then navigating to the following... (2 Replies)
Discussion started by: punpun777777
2 Replies

2. Programming

Query result from shell script

Hi, I wrote the below script to get the query result from a Syabase DB. isql -s -U **** -P **** SYBASE SERVERNAME USE ***(Database name in Sybase) @command.sql But im not getting the output. Can anyone help me on this (2 Replies)
Discussion started by: rohan G
2 Replies

3. Shell Programming and Scripting

Executing program with Perl script but needs user input

Hello, I'm running a perl script to execute a program through my Unix command line. The program requires a user input but I want to automatically have perl input the string. Is there a way to do this? Thanks (1 Reply)
Discussion started by: leonard2352
1 Replies

4. Shell Programming and Scripting

prevent ssh from executing result in shell

Hi, I am writing a script on Solaris 10 and want to execute a remote ssh command. Normally this command should just return the value 0000000000002356 but when using ssh it seems it is passing the result to the shell to execute. ssh root@10.5.112.145 `/usr/bin/nawk -F\, '$1=="USG" && $2=="01"... (3 Replies)
Discussion started by: borderblaster
3 Replies

5. Homework & Coursework Questions

A function in shell script,how can i get the right result

there is a directory /data/users/osa/psidp/dmp/files/cimdir ,it have some subdirectories ,and also the subdirectoriy have it's subdirectoriis. I want to get all the leaf nodes of the directory path . but the result of the script is wrong ,how can i get the right result somebody who can help... (1 Reply)
Discussion started by: fw0037
1 Replies

6. Shell Programming and Scripting

Executing shell program from a web page

Hi, I am looking for a cgi-script which runs a shell script from a web page. When I click "Run" from a web page it should run the shell commands in an textarea and results should get back to web page. Thanks Venkat (5 Replies)
Discussion started by: venkatritch
5 Replies

7. UNIX for Advanced & Expert Users

Advantage of executing program in user shell?

Hi, I'm curious about the advantage of forking and executing a program in a user shell as opposed to forking and executing the program directly without the user shell. For example: why is it often like: SSHD->fork&exec(shell, sftp-server)->fork&exec(sftp-server) And Not like: ... (2 Replies)
Discussion started by: seeker333
2 Replies

8. Shell Programming and Scripting

Could any one tell me how to do get result in fraction in shell script

Could any one tell me how to do get result in fraction in shell script. I am using expr for division of 2 number but it is giving Quitent. I need it in full fraction value. please helpp. how to do it using "dc" or "bc" (5 Replies)
Discussion started by: Neerajjaiswal
5 Replies

9. UNIX for Dummies Questions & Answers

meaning of columns in the result of executing 'ls -l'

Hello all, I do not understand the meaning of some columns in the result of executing 'ls -l'. For example, i got the following result by run 'ls -l' total 3531 -rw-r--r-- 1 root root 1351680 Oct 17 20:50 fileindex.rpm -rw-r--r-- 1 root root 16384 Oct 17 20:50 groupindex.rpm ... (5 Replies)
Discussion started by: cy163
5 Replies

10. UNIX for Advanced & Expert Users

executing script by cron doesnt give me expected result

Hi frnds... I m facing very irritating problem already waisted my 2 days.. I have a following script..( i am pasting only the main code) ftp -ivn 213.194.40.77 <<FTP user $user $password binary cd $FileDir/out lcd $localpath get $file rename $FileDir/out/$file $FileDir/tmp/$file... (1 Reply)
Discussion started by: clx
1 Replies
Login or Register to Ask a Question