chown directory in bash

帅比萌擦擦* 提交于 2020-01-03 05:48:20

问题


I am trying to chown a home directory test for an bash script. I need this functionality because of syncthing which is not syncing the ownerships.

#!/bin/bash

user=test

"chown $user:$user /home/$user"

When I use the above script, I get a message "test.sh: line 5: chown test:test ~/home/test/: No such file or directory "

Output of

ls -l /home/ |grep test
drwx------   5 pwresettest     1005  121  2. Nov 04:23 pwresettest
drwx------  14 test            1001 4096 29. Okt 05:41 test

When I am using the command on the commandline, it works without problems.

Did I do something wrong?


回答1:


The shell treats the quoted string as a single word to as the name of the command, rather than a command name followed by arguments. Simply take off the quotes you've added in your script:

#!/bin/bash

user=test

chown $user:$user /home/$user



回答2:


When you use chown on the command line you aren't quoting the entire command. Don't do that in the script either. – Etan Reisner



来源:https://stackoverflow.com/questions/33480688/chown-directory-in-bash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!