我試圖讀出名爲directorylist的文件的某一行。將某行文件寫入變量
我試圖調試它,但沒有找到任何幫助。看起來,命令變量不是它應該是的「6p」。
(計數器是6現在)
p=p
command="$counter$p"
user= sed -n '$command' directorylist
chown $user:$user /home/$user
那些有人知道問題出在哪裏?
在此先感謝
EDIT1:
您好,感謝的快速響應。
這是迄今爲止整個腳本:
#!/bin/bash
rm -f directorylist
touch directorylist
array=($(ls /home))
printf "%s\n" "${array[@]}" >> directorylist
counter= wc -l <directorylist
recounter=0
while [[ $recounter != $counter ]]
do
((recounter=recounter+1))
p=p
command="$counter$p"
user= sed -n '$command' directorylist
chown $user:$user /home/$user
done
EDIT2:
出於某種原因,在可變寫作 「ommand」:
chown: invalid user: ‘ommand:ommand’
EDIT3:
你說得對,問題與報價。
但仍有兩件事情我不明白第一:
chown: cannot access ‘random’: No such file or directory
這個目錄肯定是存在的。
其次是事實,它似乎忽略了循環條件。
到目前爲止有六個用戶(以及六個主目錄)。第一個計數器就是這個數字。第二個從零開始,並繼續上升一個。只要不相等,循環應該繼續。但是,這隻需要6個循環。 :/
Edit4:
好像
command="$counter$p"
排空是出於某種原因$計數器。
所以命令變量只包含「p」。
不要發明自己的語法。閱讀命令替換。 https://www.gnu.org/software/bash/manual/bash.html#Command-Substitution – 4ae1e1
呵呵,引用,這也是錯誤的。 https://www.gnu.org/software/bash/manual/bash.html#Quoting – 4ae1e1
這裏還需要更多的上下文。 $ counter從哪裏來,$ p的用途是什麼 - 我可以向你展示正確的語法,但並非沒有一個有意義的例子。 – asimovwasright