Unix 如何创建具有777权限的文件?

Unix 如何创建具有777权限的文件?,unix,Unix,在下面的脚本中,如何添加chmod 777,以便使用777权限创建文件 file="New_file.txt";cd \abc\efg\; if [ ! -f $file ] ; then touch $file; fi; 看起来很明显: file="New_file.txt" cd "your_dir" if [ ! -f "$file" ]; then touch "$file" chmod 777 "$file" fi 注意:您应该在cd中引用变量和,这样您就不必转义。

在下面的脚本中,如何添加
chmod 777
,以便使用777权限创建文件

file="New_file.txt";cd \abc\efg\;  if [ ! -f $file ] ; then touch $file;  fi;

看起来很明显:

file="New_file.txt"
cd "your_dir"
if [ ! -f "$file" ]; then
   touch "$file"
   chmod 777 "$file"
fi
注意:您应该在
cd
中引用变量和,这样您就不必转义。如果文件名包含空格、新行

一艘班轮:

file="new"; cd "your_dir"; if [ ! -f "$file" ]; then touch "$file"; chmod 777 "$file"; fi
试试这个:

file="New_file.txt"; cd /abc/efg/; if [ ! -f $file ] ; then touch $file;  chmod 777 $file; fi

您需要修改cd“abc efg”,它缺少“/”谢谢。。。但是
cd\abc\efg\
不是有效的表达式。cd\abc\efg\是文件路径,但它将忽略您的“\”,如果当前目录中存在类似于abcefg目录的内容,您将得到类似于abcefg目录的结果。您真的在使用“cd\abc\efg”吗?此外,如果文件已经存在,是否必须应用chmod 777?如果在拥有所有权限的文件夹中不存在,我必须创建文件!但这种情况只发生一次!无论如何,我已经解决了我的问题!谢谢