How to execute commands read from another file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to execute commands read from another file?
# 1  
Old 03-15-2010
Question How to execute commands read from another file?

Please help with this simple example. I can not figure out how to do it. A file named “job” contains only this one line:
Code:
var=5

I need a script to read the job file and execute it as a command. This is my attempt (it does not work):
Code:
#!/bin/sh
exec < job
echo "var = $var"

output should read “var = 5”

Thank you.
# 2  
Old 03-15-2010
Bug

Use the following shell script.It will be useful for your requirement.

Code:
 
var=10 
echo $var 
. job 
echo "var=$var"

job file contains

var=5
# 3  
Old 03-15-2010
rekha_sri,

I ran the code you suggested, but the script did not find the file "job" file
Code:
wolf-PC:~/computer_languages/UNIX/sp> ./exe_str
10
.: 4: job: not found

The "job" file and the "exe_str" script are both in the sp directory.

I appreciate you looking at this.
# 4  
Old 03-15-2010
rekha_siri probably meant:

Code:
var=10 
echo $var 
. ./job 
echo "var=$var"

If the directory containing the script called "job" is not in ${PATH} (or ${PATH} does not contain ".") the script will not be found even if your current working directory is that directory.
# 5  
Old 03-15-2010
Try this:

Code:
var=10 
echo $var 
source ./job 
echo "var=$var"

# 6  
Old 03-15-2010
MySQL

Thanks methyl, that workedSmilie
Code:
var=10 
echo $var 
. ./job 
echo "var=$var"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Other user should not read the file but can execute

Hi, I have one script for which I want that other user should not read the script file but can execute. Is there any method ? I tried by giving 711 but it gives Permission denied to other users. For Generic User id as a work around , I have created alias in .bashrc file and other user... (4 Replies)
Discussion started by: Amit Joshi
4 Replies

2. Shell Programming and Scripting

How to execute a batch file containing ftp commands??

hi, is there a way i can execute a batch file containing ftp commands like we execute sftp batch file. sftp -b batchfile user@server > output how to create a batch file for ftp executing command and how to run the batch file from a shell script? (2 Replies)
Discussion started by: Little
2 Replies

3. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

4. Shell Programming and Scripting

Shell: How to execute commands from another file?

I made a configuration file for my shell script in that all the values that the shell scipt needs, are defined, but I don't know how to let the shell script use those defined variables. Thank you for your help :) (3 Replies)
Discussion started by: Alkali
3 Replies

5. UNIX for Dummies Questions & Answers

how to use expect - send to execute list of commands inside a file

:)hello people i am working on some kind of PBX and i have list of telephone numbers inside a file, i have to insert these numbers into the correct command and then telnet to a remote server and execute these commands. i can read the telephone numbers and insert them into the command with no... (0 Replies)
Discussion started by: auma78
0 Replies

6. Shell Programming and Scripting

Execute commands to specific folder from input file

Hi, I have one text file input.txt, which has folders path as follows: /home/user/automate/abc /home/user/automate/abc/xyz /home/user/automate/test /home/user/automate/test2 /home/user/automate/test2/abc/Main In those folders i have .svn folder. 1) First i want to remove .svn like rm... (5 Replies)
Discussion started by: dragon.1431
5 Replies

7. UNIX for Advanced & Expert Users

Execute All Commands in A contrl File

Hi , I have a situation i need to write a while loop until the end of control file.In the control file i have a 5 lines which contains commands.how can i execute all with out waiting for the first one to complete. Ex ControlFile: ScripitName Test ScriptName Test1 ScriptName Test2 ... (1 Reply)
Discussion started by: ukatru
1 Replies

8. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

9. Shell Programming and Scripting

Pls Help-Script to execute Commands and write to excel file

Execute some commands in script and store result in excel sheet Kindly help me........... (1 Reply)
Discussion started by: Computer_baby
1 Replies

10. Shell Programming and Scripting

Can Xargs execute multiple commands of evry input file

Hello , I am trying to print the footer of evry file in the given directory with xargs command like follows ls -1 | xargs -I {} gzcat {} | tail -1 now problem with this is only last file foooter is getting printed as " | tail -1 " is getting executed for the last file. I know this can... (4 Replies)
Discussion started by: nilesrex
4 Replies
Login or Register to Ask a Question