bash中的chown目录 [英] chown directory in bash

查看:123
本文介绍了bash中的chown目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为bash脚本编写主目录测试。我需要此功能,因为同步无法同步所有权。

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"

当我使用上面的脚本时,我收到一条消息 test.sh:第5行:chown test:test〜/ home / test /:没有这样的文件或目录

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

输出

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.

推荐答案

shell将带引号的字符串作为单个单词视为命令的名称,而不是命令的名称。命令名称后跟参数。只需删除在脚本中添加的引号即可:

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

这篇关于bash中的chown目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆