ダイアログメニューにファイルが表示され、1つを選択して削除できます。

ダイアログメニューにファイルが表示され、1つを選択して削除できます。

特定のディレクトリにあるファイルを表示してから、いずれかのファイルを選択して削除できるようにしたいです。

これまでに私が見つけたものは次のとおりです。誰でも助けることができますか?

let i=0 # define counting variable
W=() # define working array
while read -r line; do # process file by file
    let i=$i+1
    W+=($i "$line")
done < <( ls -1 /home/admin/Desktop )
FILE=$(dialog --title "List file of directory /home" --menu "Chose one" 24 80 17 "${W[@]}" 3>&2 2>&1 1>&3) # show dialog and store output
clear
if [ $? -eq 0 ]; then # Exit with OK
    readlink -f $(ls -1 /home | sed -n "`echo "$FILE p" | sed 's/ //'`")
fi

ベストアンサー1

スクリプトはfromの戻り値を使用して、dialog指定されたソースディレクトリのファイル(またはディレクトリ)のリストから項目を選択します。

bashスクリプトの問題は、次を使用することです。2つの異なるディレクトリ値:

let i=0 # define counting variable
W=() # define working array
while read -r line; do # process file by file
    let i=$i+1
    W+=($i "$line")
done < <( ls -1 /home/admin/Desktop )
FILE=$(dialog --title "List file of directory /home" --menu "Chose one" 24 80 17 "${W[@]}" 3>&2 2>&1 1>&3) # show dialog and store output
clear
if [ $? -eq 0 ]; then # Exit with OK
    readlink -f $(ls -1 /home | sed -n "`echo "$FILE p" | sed 's/ //'`")
fi

人々は/home/admin/Desktopそして/home。一般的なアプローチは、これをシンボル(変数など)として扱い、不一致を取り除くことです。

#!/bin/bash
source=/home/admin/desktop 
let i=0 # define counting variable
W=() # define working array
while read -r line; do # process file by file
    let i=$i+1
    W+=($i "$line")
done < <( ls -1 $source )
FILE=$(dialog --title "List file of directory $source" --menu "Chose one" 24 80 17 "${W[@]}" 3>&2 2>&1 1>&3) # show dialog and store output
clear
if [ $? -eq 0 ]; then # Exit with OK
    readlink -f $source/$(ls -1 $source | sed -n "`echo "$FILE p" | sed 's/ //'`")
fi

これが完了したら、結果をreadlink使用できます。

この修正を含むスクリプトは不完全です。

  • 実際にファイルを削除するわけではありません
  • 削除する項目がファイルかディレクトリであるかを確認しません。
  • (2回!)の出力を使用することは、lsリストを取得する最良の方法ではありません。

おすすめ記事