簡體   English   中英

將命令 output 放入字符串

[英]Put command output into string

如果我在 Linux shell 中執行某些命令,如何將 output 存儲到字符串(變量)中以便以后使用? 我需要這個 Bash 腳本,請幫忙。

str=$(command)

result=`command`result=$(command)都將command的 output 分配給result變量。

只是為了添加其他答案,您可以直接在另一個命令中使用命令 output 而無需將其分配給中間變量。 例子:

wget https://feeds.npr.org/510289/podcast.xml -O podcast_`date +%Y-%m-%d`.xml 

簡稱

TODAY=`date +%Y-%m-%d`
wget https://feeds.npr.org/510289/podcast.xml -O podcast_${TODAY}.xml 

今天評估為

wget https://feeds.npr.org/510289/podcast.xml -O podcast_2020-11-29.xml 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM