且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

&是什么QUOT; $ 1 / *"意味着"对于文件中的$ 1 / *"

更新时间:2022-10-23 14:32:35

这是作为一个目录的第一个参数的水珠

在bash脚本参数文件传递到脚本为 $ 1,0 (这是脚本的名称),那么 $ 1 $ 2 $ 3 ...要访问所有这些你要么用自己的标签或使用的组构建体之一。对于组构造有 $ * $ @ 。 ( $ * 考虑所有的参数作为一个块,其中的 $ @ 认为它们由 $ IFS

The short bash script below list all files and dirs in given directory and its sub. What does the $1/* mean in the script? Please give me some references about it. Thanks

#!/bin/sh

list_alldir(){
    for file in $1/*
    do
        if [ -d $file ]; then
            echo $file
            list_alldir $file
        else
            echo $file
        fi
    done
}   

if [ $# -gt 0 ]; then 
    list_alldir "$1"
else
    list_alldir "."
fi

It's the glob of the first argument considered as a directory

In bash scripts the arguments to a file are passed into the script as $0 ( which is the script name ), then $1, $2, $3 ... To access all of them you either use their label or you use one of the group constructs. For group constructs there are $* and $@. ($* considers all of the arguments as one block where as $@ considers them delimited by $IFS)