Editing
Sleep in Mandarin
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== BASH 範例:下載檔案並在 1 ~ 7 秒之間隨機暫停 === 以下腳本檢查特定檔案是否存在於指定路徑中。如果檔案不存在,則從提供的 URL 下載檔案,然後在 1 到 7 秒之間隨機暫停。如果檔案已存在,則僅列印一條消息,表示找到了檔案並跳過了下載。 <pre> if [ ! -f /path/to/paper.pdf ] then curl "https://website/to/pdf" -L -o /path/to/paper.pdf sleep $((1 + RANDOM % 7)) else echo "檔案已找到。跳過下載。" fi </pre> 相同的命令可以寫成一行: <pre> if [ ! -f /path/to/paper.pdf ]; then curl "https://website/to/pdf" -L -o /path/to/paper.pdf; sleep $((1 + RANDOM % 7)); else echo "檔案已找到。跳過下載。"; fi </pre> References * [https://www.cyberciti.biz/faq/bash-check-if-file-does-not-exist-linux-unix/ How to check if file does not exist in Bash - nixCraft]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information