freemoon
V2EX  ›  Bash

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

  •  
  •   freemoon · Oct 26, 2020 · 2404 views
    This topic created in 2206 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
    freemoon
    OP
    Oct 26, 2020
    1
    木人吗
    aloxaf
    aloxaf
    Oct 28, 2020
    2
    1. 你可以手动加上前缀,比如 eval prefix_"$(declare -f a_function)"
    2. zsh 的话可以通过关联数组 functions_source 来查看函数的来源文件
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4340 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 01:11 · PVG 09:11 · LAX 17:11 · JFK 20:11
    ♥ Do have faith in what you're doing.