How to create a file with 777 permission?


In the following script, how can I add chmod 777 so that file can be created with 777 permission?

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

It looks quite obvious:

cd "your_dir"
if [ ! -f "$file" ]; then
   touch "$file"
   chmod 777 "$file"

Note you should quote variables and also in cd, so that you don't have to escape. It also prevents unexpected behaviours if the file name contain spaces, new lines...

One liner:

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