小编eis*_*son的帖子

How do I pass a wildcard parameter to a bash file

I'm trying to write a bash script that allows the user to pass a directory path using wildcards.

For example,

bash show_files.sh *
Run Code Online (Sandbox Code Playgroud)

when executed within this directory

drw-r--r--  2 root root  4.0K Sep 18 11:33 dir_a
-rw-r--r--  1 root root   223 Sep 18 11:33 file_b.txt
-rw-rw-r--  1 root root   106 Oct 18 15:48 file_c.sql
Run Code Online (Sandbox Code Playgroud)

would output:

dir_a
file_b.txt
file_c.sql
Run Code Online (Sandbox Code Playgroud)

The way it is right now, it outputs:

dir_a
Run Code Online (Sandbox Code Playgroud)

contents of show_files.sh:

#!/bin/bash

dirs="$1"

for dir in $dirs
do …
Run Code Online (Sandbox Code Playgroud)

linux parameters bash wildcard

31
推荐指数
2
解决办法
2万
查看次数

标签 统计

bash ×1

linux ×1

parameters ×1

wildcard ×1