首页 > 其他分享 >Zgo - which.go

Zgo - which.go

时间:2024-06-10 15:32:50浏览次数:11  
标签:filepath fmt args file Zgo go path os

 

package main

import (
    "fmt"
    "os"
    "path/filepath"
)

func main() {
    args := os.Args
    if len(args) == 1 {
        fmt.Println("Please provide an argument!")
        return
    }

    file := args[1]
    path := os.Getenv("PATH")
    pathSplit := filepath.SplitList(path)

    for _, dir := range pathSplit {
        fullPath := filepath.Join(dir, file)
        // Does it exist?
        fileInfo, err := os.Stat(fullPath)
        if err != nil {
            continue
        }

        mode := fileInfo.Mode()
        // Is it a regular file?
        if !mode.IsRegular() {
            continue
        }

        // Is it executable?
        if mode&0111 != 0 {
            fmt.Println(fullPath)
            return
        }
    }
}

 

标签:filepath,fmt,args,file,Zgo,go,path,os
From: https://www.cnblogs.com/zhangzhihui/p/18240704

相关文章

  • 吴恩达机器学习第二课 Advanced Learning Algorithms
    AdvancedLearningAlgorithmsweek11.1神经元和大脑1.2需求预测构建自己神经网络的时候:需要决定隐藏层的个数和每个隐藏层的神经元个数1.3图像感知像素的亮度值从0~255变化人脸识别:训练一个神经网络,以一个特征向量作为输入,输出图片中人的身份2.1神经网络中的网......
  • [AI Google] 使用 Gemini 取得更多成就:试用 1.5 Pro 和更多智能功能
    总结Google正在为超过35种语言的GeminiAdvanced订阅者推出Gemini1.5Pro。此次更新包括100万个token的上下文窗口、改进的数据分析功能和增强的多模态图像理解。新功能包括用于自然对话的GeminiLive、先进的规划工具和可定制的Gems。更新还集成了更多Googl......
  • CA Data Classification algorithm
    CAAssignment1DataClassification ImplementingPerceptronalgorithmAssessmentInformationAssignmentNumber1(of2)Weighting15%AssignmentCirculated10Feb2023Deadline3March2023at17:00SubmissionModeElectronicviaCanvasPurposeofassessm......
  • Golang-编码加密-Xor(GG)
    go语言环境搭建Golang学习日志━━下载及安装_golang下载-CSDN博客  gorunxxx.go  gobuildxxx.go 首先,cs.msf生成比特流数据. 放入xor,py脚本中进行xor加密. xor.pydefxor(shellcode,key):new_shellcode=""key_len=len(key)......
  • init_array与got劫持——[zer0pts 2020]easy strcmp
    只是在顺思路,wp参考了2位大佬文章列表|NSSCTF[Zer0pts2020]easystrcmp分析与加法-CSDN博客题目Die 虚拟机运行一下 没有输入,直接报错退出了IDA 很奇怪啊,就是一个比较从我们运行直接报错来看,我们运行时a1>1这个条件是不成立的我的最初思路就是调试把a1改了或......
  • 46.django - 多语言配置
    1.Django多语言基础知识多语言站点可以让不同语言的用户更好地使用和理解网站内容,提升用户体验和覆盖范围。为了实现多语言功能,我们将使用Django内置的国际化和本地化支持。我收集了一些知识点整理在这一部分,感兴趣的可以看看。直接跳过此部分也行。也可以看看官方文档:翻译......
  • Go - Using error variables to differentiate between input types
     packagemainimport("fmt""os""strconv")funcmain(){arguments:=os.Argsiflen(arguments)==1{fmt.Println("Notenougharguments")}vartotal,nInts,nFloatsint......
  • Ten Tips for Smarter Google Searches (十个更聪明使用 Google 搜索的技巧)
    TenTipsforSmarterGoogleSearches十个更聪明使用Google搜索的技巧 Date:Dec1,2006Articleisprovidedcourtesyof Que.Returntothearticle MostpeopleuseGoogleinaveryinefficientandoftenineffectivemanner.Ifallyoudoisenterafew......
  • Go - flag
     packagemainimport("flag""fmt")funcmain(){var(nameFlag=flag.String("name","Sam","Nameofthepersontosayhelloto")quietFlag=flag.Bool("quiet"......
  • The Imitate Google Dinosaur for the python <--CSDN @PythonWIN-->
    - Thisisasmallsoftwarebasedonpygame:    -Wehaveusedthewell-knownPythonlanguage-Iamcurrentlydeveloping ImitateGoogleDinosaurversion1.1andusingPythonasmyeditor.Nowletmeexplainindetailitsfunctions:    -F......