Why doesn't this work?
[my_user@archlinux ~]$ sudo chown -R ${whoami} /my_folder/path1/path2
chown: missing operand after ‘/my_folder/path1/path2’
Try 'chown --help' for more information.
[my_user@archlinux ~]$ sudo chown -R my_user /my_folder/path1/path2
[my_user@archlinux ~]$ ${whoami}
[my_user@archlinux ~]$ $whoami
But:
[my_user@archlinux ~]$ whoami
my_user
How to use the result of whoami
in sudo chown -R
?
Best Answer
The variable
$whoami
does not have a value. You may give it a value withbut in this case you may want to use the command substitution
$(whoami)
directly:A command substitution,
$(...)
, expands to the output of the command within (minus any trailing newline).The variable
$LOGNAME
(and/or$USER
) should have the same value as is returned bywhoami
, which means that you could also do