ディレクトリ内のすべての非表示ファイルを再表示する必要があるbashスクリプトを修正するのを手伝ってもらえないだろうか。問題はどこだ?
param='.'
for file in $param*; do
mv $file $(echo $file | sed 's/^.\(.*\)/\1/')
done
exit
ディレクトリ内のすべての非表示ファイルを再表示する必要があるbashスクリプトを修正するのを手伝ってもらえないだろうか。問題はどこだ?
param='.'
for file in $param*; do
mv $file $(echo $file | sed 's/^.\(.*\)/\1/')
done
exit
@anubhavaの答えは機能しますが、隠しファイル/フォルダーを処理するための修正された一般化されたソリューションを次に示します。
グローバル状態 (構成) に依存したり変更したりしません。
( # Execute in subshell to localize configuration changes below.
GLOBIGNORE=".:.." # Do not match '.' and '..'.
shopt -s nullglob # Expand globbing pattern to empty string, if no matches.
for f in .*; do # Enumerate all hidden files/folders, if any.
# Process "$f" here; e.g.: mv -n "$f" "${f:1}"
done
)
subshell を回避し.
たい場合は、次のアプローチを使用できます。これ..
は、一致するものがない場合 (GLOBIGNORE
たまたま が含まれている場合.:..
)に展開されていないパターンを明示的に除外します。
for f in .*; do
if [[ $f != '.' && $f != '..' && -e $f ]]; then
# Process "$f" here; e.g.: mv -n "$f" "${f:1}"
fi
done
@jthill、@anubhava、@Mike に敬意を表します。
私は自分でそのように名前を一括変更するのではなく、目に見えるシンボリック リンクを追加します。
while read f; do
ln -s "$f" "visible-${f#./}"
done <<EOD
$(find -mindepth 1 -maxdepth 1 -name '.*')
EOD