ch5.txt

来自「前面我发的那本linuxprog的随书源代码」· 文本 代码 · 共 117 行

TXT
117
字号
Chapter 5

-------------------------------------
Read Characters from the Keyboard and
Save Them as a String Variable
-------------------------------------
#!/bin/bash
clear
echo " "
echo "Enter Your First Name: "
read FirstName 

--------------------------------------
Read a Numeric Value from the Keyboard
and Save It as a Numeric Variable
--------------------------------------
#!/bin/bash
clear
echo " "
echo "Enter Your Age: "
read age 

------------------------------------
Read Both Strings and Numeric Values
from the Keyboard
------------------------------------
#!/bin/bash
clear
echo " "
echo "Enter Your First Name: "
read FirstName 
echo "Enter Your Last Name: "
read LastName 
echo "Enter Your Age: "
read age 

-----------------------------------
Prompt for User Name and Personally
Greet The User
-----------------------------------
#!/bin/bash
clear
echo " "
echo "Enter Your First Name: "
read FirstName 
echo "Hello, $FirstName"

-----------------------------------------------
Store A String Value To Another String Variable
-----------------------------------------------
#!/bin/bash
clear

declare FirstName
declare Greeting
echo $Greeting= "Hello,"
echo " "
echo "Enter Your First Name: "
read FirstName
echo "$Greeting $FirstName"

-----------------------------
Displaying a Numeric Variable
-----------------------------
#!/bin/bash
clear
echo " "
echo "Enter Your Age: "
read age 
echo "$age"

---------------------------------------
Displaying Numeric and String Variables
---------------------------------------
#!/bin/bash
clear
echo " "
echo "Enter Your First Name: "
read FirstName 
echo "Enter Your Age: "
read age 
echo "$FirstName, $age really isn't that old."

---------------------
Saving Data to a File
---------------------
#!/bin/bash
clear
echo " "
echo "Enter Your First Name: "
read FirstName 
echo "Enter Your Last Name: "
read LastName 
echo "$FirstName $LastName" > employees.dat

------------------------
Appending Data to a File
------------------------
#!/bin/bash
clear
echo " "
echo "Enter Your First Name: "
read FirstName 
echo "Enter Your Last Name: "
read LastName 
echo "$FirstName $LastName" >> employees.dat

-----------------------------------
Displaying Data Contained in a File
-----------------------------------
#!/bin/bash
clear
echo "Employee Data"
echo " "
cat employees.dat

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?