Sponsored Content
Top Forums Shell Programming and Scripting How to enter commands to the command prompt in a program Post 302427035 by freemoniez on Thursday 3rd of June 2010 03:57:59 PM
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...
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
PTKSH(1)						       perl/Tk Documentation							  PTKSH(1)

NAME
ptksh - Perl/Tk script to provide a graphical user interface for testing Perl/Tk commands and scripts. SYNOPSIS
% ptksh ?scriptfile? ... version information ... ptksh> $b=$mw->Button(-text=>'Hi',-command=>sub{print 'Hi'}) ptksh> $b->pack ptksh> o $b ... list of options ... ptksh> help ... help information ... ptksh> exit % DESCRIPTION
ptksh is a perl/Tk shell to enter perl commands interactively. When one starts ptksh a MainWindow is automaticly created, along with a ptksh command window. One can access the main window by typing commands using the variable $mw at the 'ptksh> ' prompt of the command window. ptksh supports command line editing and history. Just type "<Up>" at the command prompt to see a history list. The last 50 commands entered are saved, then reloaded into history list the next time you start ptksh. ptksh supports some convenient commands for inspecting Tk widgets. See below. To exit ptksh use: "exit". ptksh is *not* a full symbolic debugger. To debug perl/Tk programs at a low level use the more powerful perl debugger. (Just enter ``O tk'' on debuggers command line to start the Tk eventloop.) FEATURES
History Press <Up> (the Up Arrow) in the perlwish window to obtain a gui-based history list. Press <Enter> on any history line to enter it into the perlwish window. Then hit return. So, for example, repeat last command is <Up><Enter><Enter>. You can quit the history window with <Escape>. NOTE: history is only saved if exit is "graceful" (i.e. by the "exit" command from the console or by quitting all main windows--NOT by interrupt). Debugging Support ptksh provides some convenience function to make browsing in perl/Tk widget easier: ?, or h displays a short help summary. d, or x ?args, ...? Dumps recursively arguments to stdout. (see Data::Dumper). You must have <Data::Dumper> installed to support this feature. x was introduced for perl debugger compatibility. p ?arg, ...? appends "| " to each of it's arguments and prints it. If value is undef, '(undef)' is printed to stdout. o $widget ?-option ...? prints the option(s) of $widget one on each line. If no options are given all options of the widget are listed. See Tk::options for more details on the format and contents of the returned list. o $widget /regexp/ Lists options of $widget matching the regular expression regexp. u ?class? If no argument is given it lists the modules loaded by the commands you executed or since the last time you called "u". If argument is the empty string lists all modules that are loaded by ptksh. If argument is a string, ``text'' it tries to do a ``use Tk::Text;''. Packages Ptksh compiles into package Tk::ptksh. Your code is eval'ed into package main. The coolness of this is that your eval code should not interfere with ptksh itself. Multiline Commands ptksh will accept multiline commands. Simply put a "" character immediately before the newline, and ptksh will continue your command onto the next line. Source File Support If you have a perl/Tk script that you want to do debugging on, try running the command ptksh> do 'myscript'; -- or (at shell command prompt) -- % ptksh myscript Then use the perl/Tk commands to try out different operations on your script. ENVIRONMENT
Looks for your .ptksh_history in the directory specified by the $HOME environment variable ($HOMEPATH on Win32 systems). FILES
.ptksh_init If found in current directory it is read in an evaluated after the mainwindow $mw is created. .ptksh_init can contain any valid perl code. ~/.ptksh_history Contains the last 50 lines entered in ptksh session(s). PITFALLS
It is best not to use "my" in the commands you type into ptksh. For example "my $v" will make $v local just to the command or commands entered until <Return> is pressed. For a related reason, there are no file-scopy "my" variables in the ptksh code itself (else the user might trounce on them by accident). BUGS
Tk::MainLoop function interactively entered or sourced in a init or script file will block ptksh. SEE ALSO
Tk perldebug VERSION
VERSION 2.03 AUTHORS
Mike Beller <beller@penvision.com>, Achim Bohnet <ach@mpe.mpg.de> Copyright (c) 1996 - 1998 Achim Bohnet and Mike Beller. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Tk804.028 2007-05-05 PTKSH(1)
All times are GMT -4. The time now is 02:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy