我做了兩條管道;this,x="$(ls -1p | grep "/$" | tr -d "/")"從作業目錄中獲取所有子目錄,this,y="$(ls -1p | grep "/$"| grep \ | tr -d "/")"獲取作業目錄中包含空格的子目錄。
所以現在我要做的是替換包含空格的目錄的位置并將其放在最頂部,即,下面是我的子目錄:
Dir1
Dir2
Dir 3
現在Dir 3去頂部
Dir 3
Dir1
Dir1
for I in $x; do
for X in $y; do
if [[ $I == $X ]];then
sed "/"$X"/d" "$I"
fi
done
echo "$I"
done
以上是我執行該任務的回圈。它列印所有不包含空格的子目錄,但將其列印為:
Dir1
Dir2
sed: Dir: No such file or directory
Dir
sed: 3: No such file or directory
3
如果有人可以提供幫助,將不勝感激
uj5u.com熱心網友回復:
如果您更喜歡for回圈而不是find命令,那么如何:
#!/bin/bash
# 1st loop to print the dirnames containing space character
for d in */; do # loops over subdirectories under current directory
if [[ $d =~ [[:space:]] ]]; then # if the dirname contains a space character
echo "${d%/}" # then print the name removing the trailing slash
fi
done
# 2nd loop to print the dirnames without space character
for d in */; do
if [[ ! $d =~ [[:space:]] ]]; then # if the dirname does not contain a space character
echo "${d%/}"
fi
done
使用提供的示例輸出:
Dir 3
Dir1
Dir2
uj5u.com熱心網友回復:
使用 GNU 查找:
find . -mindepth 1 -type d -name '*[[:space:]]*' # spaces
find . -mindepth 1 -type d -regex '.*/[^/[:space:]] $' # no spaces
這是遞回的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/364441.html
上一篇:OBS如何記錄隱藏視窗?
