我已经试过在绝对路径中搜索用户文件,但现在我还需要为相对添加。我怎么能这样做?
#!/usr/local/bin/bash
if [ $# -eq 2 ]; then
DIR=$1
USERNAME=$2
while [ ! $(id -g $USERNAME) ]; do
echo "non-existing username, please add again "
read USERNAME
done
while [ ! -d "/home/$DIR" ]; do
echo "non-existing '$DIR' directory, please add again "
read DIR
done
echo "variable username is now $USERNAME"
echo "variable DIR is now $DIR"
echo -e "username group file"
ls -1Apl /home/$DIR | grep -v /\$ | awk -v user=${USERNAME} '$3==user{print}{}' | tr -s ' ' | cut -d ' ' -f3 -f4 -f9
else
echo "bla"
fi
答案 0 :(得分:1)
我不需要该死的绝对和相对路径与freakin'ls:/ 所以
while [ ! -d "$DIR" ]; do
和
ls -1Apl $DIR | grep -v /\$
它正在运作