How to enter commands to the command prompt in a program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to enter commands to the command prompt in a program
# 1  
Old 06-03-2010
How to enter commands to the command prompt in a program

Hey,
So I'm trying to write a program in unix to automate a process for my astrophysics research.
Basically I want the program to prompt the user for some information and store the entered string of text as a variable. I know how to do this.

This is where I need help:
Now lets say I have a command that needs to be run in the command prompt, and not in the program. How can I do that?

So for example I run the program. The program asks for the location of a certain file. The user enters the location and the program saves this text as some variable ($location).
I need the program to send the following to the command prompt: dmkeypar $location
is that doable?

---------- Post updated at 03:36 PM ---------- Previous update was at 03:18 PM ----------

Maybe if I tell you why I need to do this it will make more sense.

I have a bunch of sets of files that I want to manipulate in a similar way. Specifically I'm taking chandra satellite data files, and applying certain transformations and corrections to them. To do this I've created a recipe of the commands in UNIX I use to apply a particular transformation.
The whole recipe is about a hundred steps long. I would like to write a program so I dont have to keep entering the commands by hand, and that I only have to enter the file names or occasionally a number, which will be stored as a variable, the variable will be inserted into the recipee text, and the recipe text (with the user inputted file name) will be "entered" into the command prompt instead of back into the program.

---------- Post updated at 03:57 PM ---------- Previous update was at 03:36 PM ----------

I will be able to write my whole program easily if I can write this simple program.

When you the run the program it as you for an input.
So far the program would look like this:

#!/bin/sh

echo "Enter Location: \c"
read location


But next I want the program to input "location" into the command prompt, as if I had just opened the terminal and entered the contents of "location"

If I can achieve this I can do my whole program, since the only change will be that instead of entering merely the variable into the command prompt it enters some prescripted scripted with the variable (determined by the user input) embedded into the text.

This is all doable right?
Thanks in advance, if I can get this program to work it will save me so much time and let me actually get to the real research...
# 2  
Old 06-03-2010
Like this??? Smilie

Code:
#!/bin/sh
read -p 'Location? :'
dmkeypar $REPLY

# 3  
Old 06-03-2010
No that didnt workSmilie
# 4  
Old 06-03-2010
Okay, then I'm not getting you at all.

Specifically this:

Quote:
I have a command that needs to be run in the command prompt, and not in the program.
Could you provide some example of what you are expecting to run/see?
# 5  
Old 06-03-2010
I think there was an error in the prev post Should be

#!/bin/sh
read -p 'Location? :' REPLY
dmkeypar $REPLY

or what is wrong with this ... why do you need to prompt for the location, just pass it in from the command line

#!/bin/sh
dmkeypar $1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Auto enter for prompt messages

Hello everybody, I am coding a script, that allow the user to enter some information using prompt messages, i.e: sEpisode=1 read -e -i "$sEpisode" -p "Start download from episode: " downloadFrom sEpisode="${downloadFrom:-$sEpisode}" This code allows the user to set the download from... (4 Replies)
Discussion started by: Abu Rayane
4 Replies

2. Shell Programming and Scripting

Script to prompt user to enter data

Hi All I have a script that moves files from one dir to another dir based on date, but I would like to change it in a way that whoever is going to run to enter the dates in which files will be removed. This is my script: #!/bin/sh touch -mt 201302250000 /tmp/ref3 touch -mt 201302282359... (14 Replies)
Discussion started by: fretagi
14 Replies

3. Shell Programming and Scripting

how to prompt the user to enter an array in tcsh

Hello, I am writing a script that requires the user to enter a string of numbers: ex: 134 345 865 903 This command only allows for one variable to be entered: set "var" = $< and than once I got the array I want to change it to a list with each input on a different line: ... (1 Reply)
Discussion started by: smarones
1 Replies

4. Programming

How do i get Java commands to be recognized in command prompt?

I would like to do some of my Java programming homework at home, and when i type things such as "javac" & "java" it does not recognize it. How do i set it up so it recognizes Java coding? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

5. Programming

How do i get Java commands to be recognized in command prompt?

I would like to do some of my Java programming homework at home, and when i type things such as "javac" & "java" it does not recognize it. How do i set it up so it recognizes Java coding? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

6. AIX

"/" doesn't work on command prompt for searching commands last typed

When I use "/" to look for a particular command that I typed in the current session it says D02:-/home/user1/temp> /job ksh: /job: not found. D02:-/home/user1/temp> previously it used to fetch all the commands which had job in it.. for example subjob, endjob, joblist etc... may I... (7 Replies)
Discussion started by: meetzap
7 Replies

7. Solaris

Console - root command prompt displayed twice after hitting enter

Dear All, I hope you can help me. I have a pair of E2900's I've inherited. Both running Solaris 9. Both have LOM> consoles. The problem I'm experiencing only occurs when connected to the /dev/console tty. Whenever I hit 'Enter' for a new line, I receive two new lines: - myhost# ... (11 Replies)
Discussion started by: aleith
11 Replies

8. Shell Programming and Scripting

enter password at prompt during a script?

I'm using rsync with the "-e ssh" option so of course it asks for a password using a prompt. Is there a way to tell a script to expect a prompt, wait for it, and give a password when it arrives? There is a way to give rsync a password as part of its options using a file, but it only works with... (2 Replies)
Discussion started by: davidstvz
2 Replies

9. Shell Programming and Scripting

How to enter if-then condition on command prompt/line ?

Hi I have some trouble entering if-then condition in a single line on a command prompt in csh. Could someone show how does one do that ? eg: source .cshrc; cd $dir; pwd; test -d $backup_dir; if then mkdir -p ${backup_dir}; echo inside loop; fi; echo outside loop; mv -f... (3 Replies)
Discussion started by: mpc8250
3 Replies

10. UNIX for Advanced & Expert Users

Capturing command prompt from a C/C++ program

Hello, I would like to capture the password request of a process (like passwd or smbpasswd, ...) from a C/c++ program. My idea was to use pipes, but they capture only the stdout/stdin, not the request itself (e.g. "Enter password for user tom:" is not captured by pipes). In other words, my... (1 Reply)
Discussion started by: mousec
1 Replies
Login or Register to Ask a Question