Tải bản đầy đủ (.pdf) (10 trang)

040 wildcards in scripts kho tài liệu training

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (73.84 KB, 10 trang )

Wildcards in Shell Scripts

LinuxTrainingAcademy.com


What You Will Learn


How to use wildcards in your shell scripts.

LinuxTrainingAcademy.com


Why use wildcards?


Wildcards are great when you want to work
on a group of files or directories.

LinuxTrainingAcademy.com


Just like a regular command line.
#!/bin/bash
cd /var/www
cp *.html /var/www-just-html

LinuxTrainingAcademy.com


In a for loop


#!/bin/bash
cd /var/www
for FILE in *.html
do
echo "Copying $FILE"
cp $FILE /var/www-just-html
done
LinuxTrainingAcademy.com


Output:
Copying about.html
Copying contact.html
Copying index.html

LinuxTrainingAcademy.com


In a for loop
#!/bin/bash
for FILE in /var/www/*.html
do
echo "Copying $FILE"
cp $FILE /var/www-just-html
done
LinuxTrainingAcademy.com


Output:
Copying /var/www/about.html

Copying /var/www/contact.html
Copying /var/www/index.html

LinuxTrainingAcademy.com


In a for loop
#!/bin/bash
for FILE in *.html
do
echo "Copying $FILE"
cp $FILE /var/www-just-html
done
LinuxTrainingAcademy.com


Summary



Just like on the command line.
In a loop

LinuxTrainingAcademy.com



×