Bash script - Maitiro Ekuverenga Mushandisi Kuisa

Iyo linux verenga rairo rinoshandiswa kutora yekushandisa yekuisa kubva kumutsara wekuraira. Izvi zvinobatsira kana isu tichida kupa mushandisi kudyidzana panguva yekumhanya.

Iyo yekuverenga syntax ndeiyi:

read [options] variable_name

Tinogona ipapo kushandisa $ kusaina pamberi pezita rinoshanduka kuti uwane kukosha kwayo, i.e. $variable_name.

Bhash script Kuverenga Mushandisi Kuisa

Kutanga nekugadzira iyo faira ne .sh kuwedzera, i.k.

touch user_input.sh

Wobva wavhura wobva wafaira mune yako yaunofarira edhita uye nyora zvinotevera:

#!/bin/bash echo 'Enter your name:' read name echo 'Enter your age:' read age echo 'Hello' $name, 'you are' $age 'years old'

Iyi iri pamusoro script inotora zita remushandisi uye zera.



Ongorora:Iko hakuna kudikanwa kwekutsanangudza mhando yeshanduko iri kuverengerwa.

Kuti umhanye iri pamusoro script, vhura chinongedzo wobva wanyora:

$ sh user_input.sh Enter your name: DevQA Enter your age: 12 Hello DevQA, you are 12 years old

Kukurumidza Meseji neRavengwa Command

Kufambisa meseji neyekuverenga rairo, isu tinoshandisa -p sarudzo.

Semuyenzaniso:

$ read -p 'Enter your username: ' username

Kana isu tisingade kuti mavara aratidzwe pachiratidziri, tinofanirwa kushandisa -s sarudzo nemutemo wekuverenga. Izvi zvinobatsira kana isu tichiverenga mapassword.

Semuyenzaniso:

$ read -sp 'Enter your password: ' password

Yako bash script yekuverenga izvo zviri pamusoro zvekushandisa zvaizoita senge:

#!/bin/bash read -p 'Enter your username: ' username read -sp 'Enter your password: ' password echo -e ' Your username is $username and Password is $password'

Zvinobuda ndezvi:

$ sh user_input.sh Enter your username: devqa Enter your password: Your username is devqa and Password is secret