MyTetra Share
Делитесь знаниями!
создание файла по переменной
Время создания: 31.08.2017 20:51
Текстовые метки: knowledge
Раздел: bash - Variables
Запись: xintrea/mytetra_db_mcold/master/base/1500457940p506o1r0dq/text.html на raw.githubusercontent.com

#!/bin/sh
echo "What is your name?"
read USER_NAME
echo "Hello $USER_NAME"
echo "I will create you a file called $USER_NAME_file"
touch $USER_NAME_file


Think about what result you would expect. For example, if you enter "steve" as your USER_NAME, should the script create steve_file? Actually, no. This will cause an error unless there is a variable called USER_NAME_file. The shell does not know where the variable ends and the rest starts. How can we define this?  The answer is, that we enclose the variable itself in curly brackets:


#!/bin/sh
echo
"What is your name?"
read USER_NAME
echo
"Hello $USER_NAME"
echo
"I will create you a file called ${USER_NAME}_file"
touch
"${USER_NAME}_file"

Так же в этом разделе:
  • export
  • создание файла по переменной
  • read
 
MyTetra Share v.0.59
Яндекс индекс цитирования