如何编写文件创建脚本? [英] How to write file creation script?

查看:70
本文介绍了如何编写文件创建脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对脚本很陌生,想知道如何编写一个脚本 fileCreate,它有两个可选参数和两个输入参数,如下所示:

I am very new to scripting and would like to know how to write a script fileCreate which has two optional parameters two input arguments as shown below:

fileCreate <filename> <path>

参数表示文件名内容将被保存

<filename> parameter signifies the name of the file in which the contents will be saved

参数表示文件所在的目录结构得救.

<path> parameter signifies the directory structure where the file will be saved.

程序执行时会打开一个编辑器,用户可以输入任何内容,按指定保存.

When the program is executed it will open an editor and user can input any contents, that will be saved as specified.

如果不传参数,默认为当前目录和userfileX(userfileX为文件创建次数)

If no parameters are passed, the default is current directory and userfileX (userfileX to the number of times the file is created)

如果已经存在名称相似且内容相同的文件,则用户应该能够附加该文件,否则只会修改日期.

If there already exists a file of similar name and having same contents then the user should be able to append the file or else just the date gets modified.

推荐答案

使用 vi 作为编辑器:

Using vi as the editor:

D=${2:-.}

F=$1
if [ -z "$F" ] ; then
    X=1
    F="userfile$X"
    while [ -f "$F" ] ; do
        X=$(($X+1))
        F="userfile$X"
    done
fi

vi "$D/$F"

这篇关于如何编写文件创建脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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