regex 列出bash脚本中使用的所有命令[关闭]

xvw2m8pv  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(105)

已关闭,此问题需要更focused。它目前不接受回答。
**想改善这个问题吗?**更新问题,使其只关注editing this post的一个问题。

4天前关闭。
Improve this question
我的目标是列出bash脚本中使用的所有命令。最好使用-*参数,但不是强制性的。
例如,下一个脚本

#
# archives all service logs to one file
#
# must be run from project root
#

dest=${1:-tmp/logs-$(date +"%Y-%m-%d-%H-%M-%S").tgz}
dest=$(realpath $dest)
destname=$(basename $dest)

tmpdir=tmp/${destname%.*}
rm -rf $tmpdir
mkdir -p $tmpdir

echo "Collecting logs..."

cat meta/logs-paths.txt | grep -v -E '^$|#' | while read line
do 
    if [ ! -e $line ]
    then
        echo -e "\t$PWD/$line not found"
        continue
    fi 
    
    echo -e "\t$line..."

    # remove ./ this from beginning
    chain="$(echo "$line" | sed -e "s@^[\.\/]*@@")"

    dst=$tmpdir/$chain 
    mkdir -p $(dirname $dst)

    cp -r $line $dst 

done

echo "Packing $tmpdir --> $dest"
(
    cd $(dirname $tmpdir)
    tar -zcvf $dest $(basename $tmpdir)    
)

echo -e "\n\nSuccessful logs packing to $dest"

rm -rf $tmpdir

包含以下命令:

  • realpath
  • basename
  • rm -rf
  • mkdir -p
  • cat
  • grep -v -E
  • echo / echo -e
  • sed -e
  • cp -r
  • cd
  • tar -zcvf

我需要它的自动化文档和我的bash库的一些./configure文件。了解sudoers的此命令也很有用
你知道怎么做吗?我发现最好的是bashlex PyPI包,但它不能从循环中解析一些命令。

ovfsdjhp

ovfsdjhp1#

好吧,我几乎写了我想要的解决方案https://github.com/PasaOpasen/bash-commands-getter
现在它可能有问题,非常困难的语法情况下,不过滤参数这么好,但它的工作

相关问题