我有一個功能
function list_all () {
output=$(sort lastb.txt | tail 2 | head -n -2 | sort | uniq -f3 | tr -s " " | cut -d' ' -f1,3,5,6)
echo "$output"
}
我有第二個功能
function filter_username () {
read -p "Enter filter: " filter
output=$(list_all) | grep "^$filter")
echo "$output"
}
是否可以將管道output的輸出分配給變數?這樣我就不必重復我所做的整個作業?list_allgreplist_all
uj5u.com熱心網友回復:
list_all是一個寫入標準輸出的函式;因此,它可以單獨用作輸入grep。
filter_username() {
read -p "Enter filter: " filter
output=$(list_all | grep "^$filter")
echo "$output"
}
請注意,如果您只想立即將 的內容寫入output標準輸出并且不對其進行任何其他操作,則在任何一種情況下都不需要命令替換。
list_all () {
sort lastb.txt | tail 2 | head -n -2 | sort | uniq -f3 | tr -s " " | cut -d' ' -f1,3,5,6
}
filter_username () {
read -p "Enter filter: " filter
list_all | grep "^$filter"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/465460.html
標籤:重击
上一篇:從檔案中提取數字
