Why can't I use “$whoami” as a variable in “chown $whoami path”?
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
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
?
bash variable
add a comment |
up vote
-1
down vote
favorite
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
?
bash variable
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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
?
bash variable
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
?
bash variable
bash variable
edited Nov 17 at 19:44
ilkkachu
53.7k781146
53.7k781146
asked Nov 17 at 18:57
nylypej
1294
1294
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
5
down vote
The variable $whoami
does not have a value. You may give it a value with
whoami=$(whoami)
but in this case you may want to use the command substitution $(whoami)
directly:
sudo chown -R "$(whoami)" /my_folder/path1/path2
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 by whoami
, which means that you could also do
sudo chown -R "$LOGNAME" /my_folder/path1/path2
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
The variable $whoami
does not have a value. You may give it a value with
whoami=$(whoami)
but in this case you may want to use the command substitution $(whoami)
directly:
sudo chown -R "$(whoami)" /my_folder/path1/path2
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 by whoami
, which means that you could also do
sudo chown -R "$LOGNAME" /my_folder/path1/path2
add a comment |
up vote
5
down vote
The variable $whoami
does not have a value. You may give it a value with
whoami=$(whoami)
but in this case you may want to use the command substitution $(whoami)
directly:
sudo chown -R "$(whoami)" /my_folder/path1/path2
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 by whoami
, which means that you could also do
sudo chown -R "$LOGNAME" /my_folder/path1/path2
add a comment |
up vote
5
down vote
up vote
5
down vote
The variable $whoami
does not have a value. You may give it a value with
whoami=$(whoami)
but in this case you may want to use the command substitution $(whoami)
directly:
sudo chown -R "$(whoami)" /my_folder/path1/path2
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 by whoami
, which means that you could also do
sudo chown -R "$LOGNAME" /my_folder/path1/path2
The variable $whoami
does not have a value. You may give it a value with
whoami=$(whoami)
but in this case you may want to use the command substitution $(whoami)
directly:
sudo chown -R "$(whoami)" /my_folder/path1/path2
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 by whoami
, which means that you could also do
sudo chown -R "$LOGNAME" /my_folder/path1/path2
answered Nov 17 at 19:01
Kusalananda
116k15218352
116k15218352
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482379%2fwhy-cant-i-use-whoami-as-a-variable-in-chown-whoami-path%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown