Create a script that will open a file for editing
1.If no argument is given it will ask the user for a file name otherwise, it will open a file for editing.
If the file already exist it will be opened for editing.
If a file does not exist it will open a file with the following settings
#!/bin/bash already written on it
default permissions will be updated to –rwx------
Assuming the editor is vi
, you don't need a script. Just vi filename
will do as you want. Then set umask
to set files creation permission as you require.
However if you really want to script this:
input_file=${1}
## Check file exists
if [ ! -f ${input_file} ]
then
## Doesnt exist - create empty file and set permission
> ${input_file}
chmod 700 ${input_file}
fi
## Edit the file
vi ${input_file}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.