delfunction Mytest
function Mytest()
if has('win32')
!dir > 1.txt
else
let sc = "if [[ \$(who am i) =~ \\([-a-zA-Z0-9\\.]+\\)\$ ]] ; then echo SSH; else echo no; fi"
let sc1 = "who mom likes"
let sc2 = "ls -l"
let sc3 = "whoami"
let sc4 = "cat /proc/$PPID/status | head -1 | cut -f2"
let v1 = system(sc1)
echo v1
if v1 == "SSH"
echo "call from remote machine"
else
echo "call from local machine"
endif
echo "is end"
endif
endfunctionvim 脚本测试
最新推荐文章于 2026-02-15 02:17:04 发布
本文介绍了一个简单的跨平台Shell脚本示例,该脚本根据运行环境的不同(Windows或Unix-like系统)执行特定的操作。在Windows环境下,脚本会创建一个名为1.txt的文件;而在Unix-like系统中,则通过一系列命令判断当前用户是否通过SSH登录,并输出相应的信息。
2406

被折叠的 条评论
为什么被折叠?



