Identifying interactive scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Identifying interactive scripts
# 1  
Old 11-07-2016
Identifying interactive scripts

so for the purposes of this thread, interactive scripts are shell scripts that prompts for a response from a user and then waits for the user to enter a response before proceeding.

now, from my understanding of this, the one common string i can expect to find in all interactive scripts is some variation of this:

Code:
read -p "Would you like to proceed? [y/n]: " yn


notice i bolded the "read -p".

the reason i'm asking about this is, i need to add a line to every line that contains the pattern "read -p" or any other pattern that can be used to identify interactive scripts.

the line i need to add after every line that identifies a script as interactive should be:

Code:
exec < /tmp/roles > /dev/roles

below is command im using:

Code:
awk '{print} /read -p/ {while (getline < "exec < /tmp/roles > /dev/roles" ) print}' thescript.sh > the_interactive_script.sh


Question:

1. Also, are there any other patterns I can look for to help me identify if a script is an interactive script?

Last edited by SkySmart; 11-07-2016 at 02:12 AM..
# 2  
Old 11-07-2016
There are an unlimited number of patterns you could look for that are common to all POSIX conforming shells. There are others that are specific to specific shells. There are others that are specific to certain versions of certain shells.

Adding the line you say you want to add in the place you say you want to add it will be a syntax error in many cases. You CAN NOT add fixed text in a fixed position after a prompt is written and a response is read without fully understanding the context of the code in question. For example:
Code:
printf 'Initial prompt for filename: '
while IFS= read -r answer
do	# Validate response...
	if [ -r "$answer" ]
	then	break
	fi
	printf '"%s" is not readable.\nSecondary prompt for filename: ' "$answer"
done

will not work if you insert your new statement after the while before the do.

Note also that most of the code you could be used to produce prompts in an interactive script can, with appropriate file redirections, be used in a non-interactive script with the prompt being redirected to a log file and the response being read from a configuration file.

Note also that interactive programs can be written in C, C++, FORTRAN java, awk, and hundreds of other programming and scripting languages; and sticking shell code into the middle of an object file or into the source of an interactive program that is not a shell script will not work.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Identifying a process

morning, i introduce the following sentence: "sudo lsof -i | grep smtp" ang get a list of the processes. two of them i don't know what is the function: 29574 & 29575, with the following indication: "memo" the rest of the processes shown are smtpd. i kill these two processes and they disappear,... (4 Replies)
Discussion started by: brijan007
4 Replies

2. Shell Programming and Scripting

Bash -c interactive scripts

i have to run the following script through a pipe: script.sh: #!/bin/bash echo "Hello World" echo -e "The \033 here's how its currently being run: bash -c "$(cat script.sh)" This is an interactive script. the problem is, when i run it this way, if you go to another terminal and... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. Shell Programming and Scripting

Bash interactive scripts

i have a script that contains: script.sh #!/bin/bash echo -e "\t\t\t0. Exit" echo -e "\t\t\t1. Help" echo -e "\t\t\t2. Notes" echo -e "\t\t\t3. Classes" echo "${newline}" echo -n -e "\t Please enter option number : " read Type case $Type in 1) clear ... (1 Reply)
Discussion started by: SkySmart
1 Replies

4. Shell Programming and Scripting

interactive scripts with user input that includes quotes

I'm writing a basic ldapsearch script that prompts the user for their search criteria. The input they're being asked for is the search filter portion of the ldapsearch command. This string must be quoted. When the script executes the command it returns nothing. If I hard code a search filter it... (1 Reply)
Discussion started by: donniemac
1 Replies

5. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

6. Shell Programming and Scripting

Interactive scripts for Oracle

Hello friends, I am a ORACLE user, we have some internal database file, lets say "demo.config" and an internal tool to patch this file....lets call that tool as "dbfixer". We have 100's-1000's of such files "demo.config" which need to get patched by the tool. So we need to write a script ...... (1 Reply)
Discussion started by: Newbie456267uni
1 Replies

7. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

8. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

9. Shell Programming and Scripting

Automating interactive scripts

Hi all, I am trying to write a program that will automate interactive scripts that use 'pkgadd'. Easily enough I can use 'pkgask' and a response file for most of what I want to do, but unfortunately there are parts of some pkg installations that are configured to only take input from /dev/tty!!... (2 Replies)
Discussion started by: bookoo
2 Replies
Login or Register to Ask a Question