#! /Users/zhijiayou02/v/src/vfor _ in0 .. 5 {println('V script')}println('deploying...')println('Files')foo :=ls('.') or { panic(err) }println(foo)println('')rm('a.out') or { panic(err) }println('Making dir name and creating foo.txt')mkdir('name')!create('foo.txt')!foo_ls :=ls('.') or { panic(err) }println(foo_ls)println('')println('Entering into name')chdir('name') or { panic(err) }foo_ls2 :=ls('.') or { panic(err) }println(foo_ls2)println('')println('Removing name and foo.txt')println('')chdir('../') or { panic(err) }rmdir('name') or { panic(err) }rm('foo.txt') or { panic(err) }again :=ls('.') or { panic(err) }println(again)
#!/usr/local/bin/v //跟shell脚本一样,可以使用#!来设置执行此脚本的工具,也是要提前设置为可执行:chmod +ximport os// use system default C compiler if foundmut cc :='cc'if os.args.len >=2 {if os.args[1] in ['cc','gcc','clang','msvc'] { cc = os.args[1] } else {println('> Usage error: parameter must be in cc/gcc/clang/msvc')return }}println('> Building VLS...')ret :=system('v -gc boehm -cg -cc $cc cmd/vls -o vls') //可以直接使用os模块内部的函数,就像内置函数那样,不用模块前缀if ret !=0 {println('Failed building VLS')return}println('> VLS built successfully!')