小编sky*_*das的帖子

在Bash中使用案例模式中的空格

我需要找到在模式中使用空间的解决方案case.我有这个功能case

  setParam() {
    case "$1" in
          0624)
            # do something - download file from url
          ;;
          del-0624)
            # do something - delete file from local machine
            exit 0
          ;;
      # Help
          *|''|h|help)
            printHelp
            exit 0
          ;;
    esac
  }

  for PARAM in $*; do
    setParam "$PARAM"
  done
Run Code Online (Sandbox Code Playgroud)

Paramter "0624"用于从url下载文件的运行功能.Paramter "del-0624"用于删除本地计算机中的文件.

问题:可以使用参数"del 0624"(带空格)吗?我在参数中有空间问题case.

bash

4
推荐指数
1
解决办法
3186
查看次数

Bash:从文件列表中下载文件

我有一个名为files.txt的文件,其中包含我要下载的所有文件.

files.txt

http://file/to/download/IC_0000.tpl
http://file/to/download/IC_0001.tpl
Run Code Online (Sandbox Code Playgroud)

如果我使用

cat files.txt | egrep -v "(^#.*|^$)" | xargs -n 1 wget
Run Code Online (Sandbox Code Playgroud)

所有文件都已下载.

但我不知道如何使用If files.txt只包含没有http的文件

files.txt

IC_0000.tpl
IC_0001.tpl
Run Code Online (Sandbox Code Playgroud)

我只对这个参数"wget":

Usage: wget [-c|--continue] [-s|--spider] [-q|--quiet] [-O|--output-document FILE]
        [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]
        [--no-check-certificate] [-U|--user-agent AGENT] [-T SEC] URL...
Run Code Online (Sandbox Code Playgroud)

你能帮我吗.

非常感谢.

bash

1
推荐指数
1
解决办法
1520
查看次数

标签 统计

bash ×2