I am trying to read out a certain line of a file called directorylist.
I tried to debug it but I found nothing that helped. It just seemed, that the command variable is not the "6p" it should be.
(The counter is 6 by now)
p=p
command="$counter$p"
user= sed -n '$command' directorylist
chown $user:$user /home/$user
Those someone know where the problem is?
thanks in advance
Edit1:
Hi , thanks for the fast respond.
That is the whole script so far:
#!/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:
For some reason it is writing "ommand" in the variable:
chown: invalid user: ‘ommand:ommand’
Edit3:
You were right, the problem were with the quotes.
But there are still two things I do not get first:
chown: cannot access ‘random’: No such file or directory
This directory is certainly existing.
Secondly is the fact, that it seems to ignore the loop conditions.
There are six users so far (as well as six home directories). The first counter is this number. The second one start at zero and continues to go up by one. The loop should continue as long as there are not equal. But that should only take 6 loops. :/
Edit4:
It seems like
command="$counter$p"
Is emptying $counter for some reason.
So the command variable just contains "p".