Shell Script - insert variable in a command

Asked

Viewed 740 times

2

Hello, first I want to say that I am beginner in shell script. My doubt is: I have a script that will execute a series of commands, one of these commands is an "input" in which asks me to type a name, I wonder if there is a possibility to create a variable containing this name and when the command asks for this name will be inserted.

Thank you in advance!

2 answers

2


You can use parameters for this, for example when running:

./script_teste parametro_1 parametro_2

Being script_teste the bash script below:

#!/bin/bash

echo 'Parametros passados:'
echo '$1 =' $1
echo '$2 =' $2

The exit would be:

Parametros passados:
$1 = parametro_1
$2 = parametro_2

1

I don’t know if I understood correctly, but if input is needed I could use read.

#!/bin/bash

read -p "Input: " input # A opção -p faz com que possa digitar na mesma linha

echo "${input}" # Utilizar a variável entre chaves para proteger

Browser other questions tagged

You are not signed in. Login or sign up in order to post.