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[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:

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.

How about

bash < script.sh

Or even the popular, old fashioned

bash script.sh

Or perhaps the old standby

./script.sh
1 Like

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

bash -c "$(cat script.sh)"

And, why are you running:

bash -c "$(cat script.sh)"

instead of running:

./script.sh

or, if your current working directory is in your setting for $PATH , just:

script.sh

either by itself or if it is an element in a pipeline?

1 Like

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

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?

1 Like