Ana Sayfa / Linux / Bash Script / Hello World with User Input / Kullanıcı Girişi İle Merhaba Dünyaz Yazdırma

Hello World with User Input / Kullanıcı Girişi İle Merhaba Dünyaz Yazdırma

The following will prompt a user for input, and then store that input as a string (text) in a variable. The variable is
then used to give a message to the user.

#!/usr/bin/env bash
echo "Who are you?"
read name
echo "Hello, $name."

The command read here reads one line of data from standard input into the variable name. This is then referenced using $name and printed to standard out using echo.

Example output:

$ ./hello_world.sh
Who are you?
Matt
Hello, Matt.

Here the user entered the name “Matt”, and this code was used to say Hello, Matt..


And if you want to append something to the variable value while printing it, use curly brackets around the variable
name as shown in the following example:

#!/usr/bin/env bash
echo "What are you doing?"
read action
echo "You are ${action}ing."

Example output:

$ ./hello_world.sh
What are you doing?
Sleep
You are Sleeping.

Here when user enters an action, “ing” is appended to that action while printing.

Bunada Göz Atın

PHP Types

Type Comparison There are two types of comparison: loose comparison with == and strict comparison …

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir