freemoon
V2EX  ›  Bash

shell 中的 import 能不能支持 as 或 alias 类似功能

  •  
  •   freemoon · Oct 26, 2020 · 2061 views
    This topic created in 2031 days ago, the information mentioned may be changed or developed.

    在一个脚本中 import 了较多外部脚本,然后调用他们的函数,问题来了,在给别人看这个脚本的时候他会觉得一脸懵逼,不知道这个函数到底来自哪个引入的脚本,非得全局搜索?有没有较好的办法解决这个问题?

    source x1.sh
    source x2.sh
    
    2 replies    2020-10-28 10:30:18 +08:00
    freemoon
        1
    freemoon  
    OP
       Oct 26, 2020
    木人吗
    aloxaf
        2
    aloxaf  
       Oct 28, 2020
    1. 你可以手动加上前缀,比如 eval prefix_"$(declare -f a_function)"
    2. zsh 的话可以通过关联数组 functions_source 来查看函数的来源文件
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   977 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:22 · PVG 04:22 · LAX 13:22 · JFK 16:22
    ♥ Do have faith in what you're doing.