我正在嘗試撰寫一個 bash 腳本來將所有.desktop檔案復制/nix/store到~/.local/share/applications/. 我對 bash 不是特別好,所以我需要幫助。我使用該find命令查找所有檔案。現在我正在嘗試在以下幫助下從輸出中創建一個陣列readarray:
files=$(find /nix/store -type f -name \*.desktop)
echo $files
x=$(readarray -d 's' <<<$files)
echo $x
將echo $files列印find命令的結果,但是echo $x列印一個空行。
uj5u.com熱心網友回復:
#!/usr/bin/env bash
files=$(find /nix/store -type f -name \*.desktop)
readarray array <<<$files
for i in ${array[@]}; do
cp $i ~/.loca/share/applications/
done
要么
find /nix/store -type f -name \*.desktop -exec cp {} ~/.local/share/applications/ \;
uj5u.com熱心網友回復:
將所有 .desktop 檔案復制到 ~/.local/share/applications/
find /nix/store -type f -name '*.desktop' \
-exec cp -v {} ~/.local/share/applications/ ';'
但是 echo $x 列印一個空行。
readarray不產生任何輸出。相反,它將行存盤在引數中,該引數表示變數的名稱,陣列的名稱。
readarray -d 's' <<<$files
# ^^^ - stores output in array named s
printf "%s\n" "${s[@]}" # you can print the array s
uj5u.com熱心網友回復:
如果我沒記錯并且 /nix/store/ 是一個常規目錄,這應該可以作業:
cp /nix/store/*.desktop ~/.local/share/applications/
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/446321.html
上一篇:使用“批處理”命令運行批處理檔案
