1

Let say I have this line in a shell script in unix:

read -n 1

It will prompt the user to get value but is there a way to call the script so it takes the input as argument instead?

Like this for example:

myscript.sh "M"

I want to call the script from a build engine so it cannot answer with keyboard input.

4 Answers 4

2

To use argument values in shell script you can pass the argument with the script and then refer them using $1, $2, $3 and so on.

Sign up to request clarification or add additional context in comments.

Comments

2

You can use Here Strings in bash:

myscript.sh <<< "M"

Or use pipeline:

echo "M" | myscript.sh

Here string documentation

2 Comments

I've been looking for ages for that, what are the keywords we can use?
It shows up under Here Strings section in man bash. Or you can check link I have added in my answer.
0

Use this with some frequency:

hello() {  read -n1 CHAR;  echo $CHAR; }
echo world | hello

Comments

0

How about

myscript.sh $(read -n 1)

?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.