The shiftcommand shifts the parameter variables so that what would ord dịch - The shiftcommand shifts the parameter variables so that what would ord Việt làm thế nào để nói

The shiftcommand shifts the paramet

The shiftcommand shifts the parameter variables so that what would
ordinarily be $2becomes $1, what would be $3becomes $2, and so on.
Adding a number, as in shift 3, shifts the assignments by that number of
units. The shiftcommand does not alter the $0variable, though. You can
use shiftin conjunction with a loop (described later, in “Using Loops”)
to examine all of the parameters passed to a script, in case their order or
number is unknown when you write the script.
As an example of how a script with a parameter variable can help in such situations,
consider Listing 9.2. This script creates an account and changes the account’s password
(you’ll be prompted to enter the password when you run the script). It creates a directory
in the /shareddirectory tree corresponding to the account, and it sets a symbolic link to
that directory from the new user’s home directory. It also adjusts ownership and permissions in a way that may be useful, depending on your system’s ownership and permissions
policies.
438 Chapter 9 ■ Writing Scripts, Configuring Email, and Using Databases
Listing 9.2: A script that reduces account-creation tedium
#!/bin/sh
useradd -m $1
passwd $1
mkdir -p /shared/$1
chown $1.users /shared/$1
chmod 775 /shared/$1
ln -s /shared/$1 /home/$1/shared
chown $1.users /home/$1/shared
If you use Listing 9.2, you need type only three things: the script name with the desired
username and the password (twice). For instance, if the script is called mkuser, you can use
it like this:
# mkuser ajones
Changing password for user ajones
New password:
Retype new password:
passwd: all authentication tokens updated successfully
Most of the scripts’ programs operate silently unless they encounter problems, so the
interaction (including typing the passwords, which don’t echo to the screen) is a result of
just the passwdcommand. In effect, Listing 9.2’s script replaces seven lines of commands
with one. Every one of those lines uses the username, so by running this script, you also
reduce the chance of a typo causing problems.
Another type of variable is assigned within scripts—for instance, such variables can
be set from the output of a command. These variables are also identified by leading dollar signs, but they’re typically given names that at least begin with a letter, such as $Addr
or $Name. (When values are assigned to variables, the dollar sign is omitted, as illustrated
shortly.) You can then use these variables in conjunction with normal commands as if they
were command parameters, but the value of the variable is passed to the command.
For instance, consider Listing 9.3, which checks to see whether the computer’s router is
up with the help of the pingutility. This script uses two variables. The first is $ip, which
is extracted from the output of routeusing the grep, tr, and cutcommands. (These
commands are described in Chapter 1.) When you’re assigning a value to a variable from
the output of a command, that command should be enclosed in back-tick characters (`),
which appear on the same key as the tilde (~) on most keyboards. These are notordinary
single quotes, which appear on the same key as the regular quote character (“) on most
keyboards. The second variable, $ping, simply points to the pingprogram. It can easily be
omitted, with subsequent uses of $pingreplaced by the full path to the program or simply
by ping(relying on the $PATHenvironment variable to find the program). Variables like this
are sometimes used to make it easier to modify the script in the future. For instance, if you
0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
The shiftcommand shifts the parameter variables so that what would ordinarily be $2becomes $1, what would be $3becomes $2, and so on. Adding a number, as in shift 3, shifts the assignments by that number of units. The shiftcommand does not alter the $0variable, though. You can use shiftin conjunction with a loop (described later, in “Using Loops”) to examine all of the parameters passed to a script, in case their order or number is unknown when you write the script.As an example of how a script with a parameter variable can help in such situations, consider Listing 9.2. This script creates an account and changes the account’s password (you’ll be prompted to enter the password when you run the script). It creates a directory in the /shareddirectory tree corresponding to the account, and it sets a symbolic link to that directory from the new user’s home directory. It also adjusts ownership and permissions in a way that may be useful, depending on your system’s ownership and permissions policies.438 Chapter 9 ■ Writing Scripts, Configuring Email, and Using DatabasesListing 9.2: A script that reduces account-creation tedium#!/bin/shuseradd -m $1passwd $1mkdir -p /shared/$1chown $1.users /shared/$1chmod 775 /shared/$1ln -s /shared/$1 /home/$1/sharedchown $1.users /home/$1/sharedIf you use Listing 9.2, you need type only three things: the script name with the desired username and the password (twice). For instance, if the script is called mkuser, you can use it like this:
# mkuser ajones
Changing password for user ajones
New password:
Retype new password:
passwd: all authentication tokens updated successfully
Most of the scripts’ programs operate silently unless they encounter problems, so the
interaction (including typing the passwords, which don’t echo to the screen) is a result of
just the passwdcommand. In effect, Listing 9.2’s script replaces seven lines of commands
with one. Every one of those lines uses the username, so by running this script, you also
reduce the chance of a typo causing problems.
Another type of variable is assigned within scripts—for instance, such variables can
be set from the output of a command. These variables are also identified by leading dollar signs, but they’re typically given names that at least begin with a letter, such as $Addr
or $Name. (When values are assigned to variables, the dollar sign is omitted, as illustrated
shortly.) You can then use these variables in conjunction with normal commands as if they
were command parameters, but the value of the variable is passed to the command.
For instance, consider Listing 9.3, which checks to see whether the computer’s router is
up with the help of the pingutility. This script uses two variables. The first is $ip, which
is extracted from the output of routeusing the grep, tr, and cutcommands. (These
commands are described in Chapter 1.) When you’re assigning a value to a variable from
the output of a command, that command should be enclosed in back-tick characters (`),
which appear on the same key as the tilde (~) on most keyboards. These are notordinary
single quotes, which appear on the same key as the regular quote character (“) on most
keyboards. The second variable, $ping, simply points to the pingprogram. It can easily be
omitted, with subsequent uses of $pingreplaced by the full path to the program or simply
by ping(relying on the $PATHenvironment variable to find the program). Variables like this
are sometimes used to make it easier to modify the script in the future. For instance, if you
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!
Các shiftcommand thay đổi các biến tham số để điều gì sẽ
bình thường là $ 2becomes $ 1, những gì sẽ là $ 3becomes $ 2, và như vậy.
Thêm một số, như trong ca 3, thay đổi các bài tập bằng con số của
đơn vị. Các shiftcommand không làm thay đổi $ 0variable, mặc dù. Bạn có thể
sử dụng kết hợp shiftin với một vòng lặp (mô tả sau, trong "Sử dụng Loops")
để kiểm tra tất cả các thông số được truyền cho một kịch bản, trong trường hợp đặt hàng hoặc họ
số là chưa biết khi bạn viết kịch bản.
Như một ví dụ về cách một kịch bản với một biến tham số có thể giúp đỡ trong tình huống như vậy,
xem xét Listing 9.2. Kịch bản này tạo ra một tài khoản và thay đổi mật khẩu của tài khoản
(bạn sẽ được nhắc nhở để nhập mật khẩu khi bạn chạy các script). Nó tạo ra một thư mục
trong cây shareddirectory / tương ứng với tài khoản, và nó đặt ra một liên kết tượng trưng đến
thư mục đó từ thư mục chủ của người dùng mới. Nó cũng điều chỉnh quyền sở hữu và quyền trong một cách mà có thể hữu ích, tùy thuộc vào quyền sở hữu và quyền hạn của hệ thống
chính sách.
438 Chương 9 ■ Scripts Viết, Cấu hình Email, và sử dụng cơ sở dữ liệu
Listing 9.2: Một kịch bản mà làm giảm tính sáng tạo sự nhàm
chán! # / bin / sh
useradd -m 1 $
passwd 1 $
mkdir -p / chia sẻ / 1 $
chown $ 1.users / chia sẻ / 1 $
chmod 775 / chia sẻ / 1 $
ln -s / chia sẻ / $ 1 / home / $ 1 / chia sẻ
chown $ 1.users / home / $ 1 / chia sẻ
Nếu bạn sử dụng Bảng liệt kê 9.2, bạn cần gõ chỉ có ba điều: tên kịch bản với mong muốn
tên người dùng và mật khẩu (hai lần). Ví dụ, nếu kịch bản được gọi là mkuser, bạn có thể sử dụng
nó như thế này:
ajones # mkuser
Thay đổi mật khẩu cho ajones người dùng
Mật khẩu mới:
Nhập lại mật khẩu mới:
passwd: tất cả các thẻ xác thực được cập nhật thành công
nhất của chương trình 'kịch bản hoạt động âm thầm, trừ khi họ gặp phải vấn đề, ​​vì vậy
tương tác (bao gồm cả cách gõ mật khẩu, mà không echo để màn hình) là một kết quả của
chỉ passwdcommand. Trong thực tế, kịch bản Listing 9.2 sẽ thay thế bảy dòng lệnh
với một. Mỗi một trong những dòng sử dụng tên người dùng, do đó bằng cách chạy script này, bạn cũng
làm giảm cơ hội của một lỗi đánh máy gây ra vấn đề.
Một loại biến được phân công trong kịch bản-ví dụ, các biến như vậy có thể
được thiết lập từ đầu ra của một lệnh. Các biến này cũng được xác định bởi các dấu hiệu đồng đô la hàng đầu, nhưng họ thường đưa ra những cái tên ít nhất là bắt đầu với một bức thư, chẳng hạn như $ Addr
hoặc $ Name. (Khi giá trị được gán cho biến, dấu $ được bỏ qua, như minh họa
trong thời gian ngắn.) Sau đó bạn có thể sử dụng các biến này kết hợp với các lệnh thông thường như thể họ
là các thông số lệnh, nhưng giá trị của biến được truyền vào lệnh.
Ví Ví dụ, hãy xem xét Bảng liệt kê 9.3, trong đó kiểm tra để xem liệu router của máy tính là
với sự giúp đỡ của các pingutility. Kịch bản này sử dụng hai biến. Việc đầu tiên là $ ip, mà
được chiết xuất từ các đầu ra của routeusing các grep, tr, và cutcommands. (Những
lệnh này được mô tả trong Chương 1.) Khi bạn đang gán giá trị cho một biến từ
các đầu ra của một lệnh, lệnh đó phải được kèm theo trong các nhân vật lại dấu tick (`),
trong đó xuất hiện trên cùng một phím dấu ngã (~) trên hầu hết các bàn phím. Đây là những notordinary
dấu nháy đơn, xuất hiện trên cùng một phím với các nhân vật báo thường xuyên (") trên hầu hết các
bàn phím. Các biến thứ hai, $ ping, chỉ đơn giản là chỉ vào pingprogram. Nó có thể dễ dàng được
bỏ qua, với việc sử dụng tiếp theo của $ pingreplaced bởi các đường dẫn đầy đủ đến các chương trình hoặc chỉ đơn giản
bằng cách ping (dựa trên biến $ PATHenvironment để tìm các chương trình). Biến như thế này
đôi khi được dùng để làm cho nó dễ dàng hơn để thay đổi kịch bản trong tương lai. Ví dụ, nếu bạn
đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2024 I Love Translation. All reserved.

E-mail: