Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在shell脚本中使用chmod_Shell_Chmod - Fatal编程技术网

如何在shell脚本中使用chmod

如何在shell脚本中使用chmod,shell,chmod,Shell,Chmod,这是一个shell脚本: #!/bin/bash trialName= "trial.txt" chmod a+rwx $trialName 那真的不管用。我试图在$trialName周围添加单引号/双引号,但这也不起作用。我可以这样做吗?您需要删除=后面的空格: trialName="trial.txt" # note the absence of the space between '=' and '"' chmod a+rwx "$trialName" 它有用吗?在=之间不能有空格,

这是一个shell脚本:

#!/bin/bash
trialName= "trial.txt"

chmod a+rwx $trialName

那真的不管用。我试图在
$trialName
周围添加单引号/双引号,但这也不起作用。我可以这样做吗?

您需要删除
=
后面的空格:

trialName="trial.txt" # note the absence of the space between '=' and '"'
chmod a+rwx "$trialName"

它有用吗?在
=

之间不能有空格,可能是我的错误,但是,变量声明对于bash是不正确的,另外,尝试使用
-x
选项运行脚本,您应该可以看到它失败的地方。行
trialName=“trial.txt”
是合法的,但是它将变量
$trialName
设置为空字符串,然后尝试执行命令
trial.txt
。您应该收到一条错误消息,如
trial.txt:command not found
——您真的应该告诉我们这一点。说“那真的不管用”并没有它所能起到的作用。当然,很抱歉!我会在下次提问时提供足够的信息。谢谢@超级乔希。如果这个答案对你有帮助,请点击左边的复选标记,接受这个答案。这给了你和我代表权,并帮助未来的访问者知道是什么解决了你的问题。(请注意,您必须等到首次发布后十分钟后才能接受答复。)
#!/bin/bash
TRIALNAME="trial.txt"

chmod a+rwx $TRIALNAME