读取命令行bash的水珠 [英] Read glob from command line bash

查看:91
本文介绍了读取命令行bash的水珠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读命令行bash中的一种水珠怎么​​办?我尝试这样做,它只是拿起在水珠的第一个文件:

How do I read a glob in bash from command line? I tried this and it only picks up the first file in the glob:

#!/bin/bash
shopt -s nullglob
FILES=$1
for f in $FILES
do
  echo "Processing $f file..."
  echo $f
done

比方说,我的脚本script.sh。我想这样称呼它 SH script.sh /家庭/ HSS / * 4 GZ
(其中, /家庭/ HSS / * 4 GZ 是命令行参数)。当我尝试了上面的脚本,它读取只有第一个文件。任何想法?

Let's say my script is script.sh. I want to call it like sh script.sh /home/hss/* 4 gz (where /home/hss/*, 4 and gz are the command line arguments). When I try the above script, it reads only the first file. Any ideas?

推荐答案

您需要引用调用脚本的时候,为了避免路径扩展(由当前的shell),它包含shell元字符的任何参数:

You need to quote any parameters which contain shell meta-characters when calling the script, to avoid pathname expansion (by your current shell):

sh script.sh "/home/hss/*" 4 gz

因此​​, $ 1 将被分配格局,而不是第一个匹配的文件。

Thus $1 will be assigned the pattern and not the first matched file.

这篇关于读取命令行bash的水珠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆