Bash -c interactive scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash -c interactive scripts
# 1  
Old 01-26-2017
Bash -c interactive scripts

i have to run the following script through a pipe:

script.sh:
Code:
#!/bin/bash

echo "Hello World"
echo -e "The \033[0;31merror\033[0m should be in red..."
exec </dev/tty >/dev/tty
read x
echo $x
echo "Now tell me"
read y
echo $x and $y

here's how its currently being run:

Code:
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 you type ps -efauxx, you'll see the content of this script in the process table. i want to avoid that.

is there any other way to run this script without having to run it the normal way? the goal here is to be able to pipe a script to the bash command and have it execute as it would have, had it been in a file.

Last edited by rbatte1; 01-27-2017 at 12:41 PM..
# 2  
Old 01-26-2017
How about
Code:
bash < script.sh

Or even the popular, old fashioned
Code:
bash script.sh

Or perhaps the old standby
Code:
./script.sh

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-26-2017
To expand a little bit on what Corona688 already said...
I must be missing the point.
What do you mean by run it through a pipe? There is no pipe in
Code:
bash -c "$(cat script.sh)"

And, why are you running:
Code:
bash -c "$(cat script.sh)"

instead of running:
Code:
./script.sh

or, if your current working directory is in your setting for $PATH, just:
Code:
script.sh

either by itself or if it is an element in a pipeline?
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 01-27-2017
this particular interactive script i need to run needs to be run via a pipe or via bash -c "content of the file containing the script".

I'm well aware I can just run the script the normal way. but in this scenario I'm in, I cant do that. I need to be able to run it via a pipe.

unfortunately, when you run a script with a bash -c "" and you go to another terminal, you will be able to see the content of the script in the process table with just a simple ps -efauxx

Last edited by rbatte1; 01-27-2017 at 12:43 PM.. Reason: Added ICODE tags for inline code.
# 5  
Old 01-27-2017
What, exactly, is this pipe carrying? Obviously not the program contents, and obviously not data input either. This means there's literally no point putting it in a pipe chain. Why is it there?
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: SkySmart
1 Replies

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

3. Shell Programming and Scripting

Bash interactive Script Required

Dear All, Please help in creating a bash script to fetch records from multiple files the script should ask inputs of file type and column level input(at least 4 col of each file type) I have 4 sort of Files, A,B,C,D. file names are like A_0112.unl, A_01215.unl, A_0001.unl and same with B C... (3 Replies)
Discussion started by: Muhammad Ali
3 Replies

4. Shell Programming and Scripting

Non interactive su in bash script

Hi, I have a python gui which allow users entering the root password, then a bash script is called to run "su" with the root password on the background. I could find a way to run "su" with a password. How to run "su" in a bash script without password prompt? Thank you. (4 Replies)
Discussion started by: hce
4 Replies

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

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. Shell Programming and Scripting

Bash interactive installation script

Hi, for an exercise I need to write a script that will ask the user about each package in a (local) repository and install it or not according to the user's input. I am fairly new to scripting, so I did not get very far. Here is what I came up with. I really appreciate your help. ... (1 Reply)
Discussion started by: Softsmid
1 Replies

8. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 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