用变量替换命令?
Replacing commands with a variable?
#!/bin/bash
```
download()
{
local url=
echo -n " "
wget -nc --progress=dot $url 2>&1 | grep --line-buffered "%" | \
sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", )}'
echo -ne "\b\b\b\b"
echo " DONE"
}
```
file="adaway.org.txt"
echo -n "Downloading $file:"
download "https://raw.githubusercontent.com/EnergizedProtection/block/master/assets/active/filter/$file"
这仍然很粗糙,但可以工作。我只是想做一些变量来缩短底部,然后让我的 bash 从 cat 文件中读取。
您的问题不清楚,但听起来您可能正在尝试这样做:
$ cat a.txt
http://google.com/foo
http://yahoo.com/stuff/bar
$ cat tst.sh
#!/bin/env bash
input=""
while IFS= read -r line; do
path="${line%/*}"
file="${line##*/}"
printf '\nline="%s"\n' "$line"
printf 'path="%s"\n' "$path"
printf 'file="%s"\n' "$file"
echo download "${path}/${file}"
done < "$input"
$ ./tst.sh a.txt
line="http://google.com/foo"
path="http://google.com"
file="foo"
download http://google.com/foo
line="http://yahoo.com/stuff/bar"
path="http://yahoo.com/stuff"
file="bar"
download http://yahoo.com/stuff/bar
如果不是,请编辑您的问题以澄清。
#!/bin/bash
```
download()
{
local url=
echo -n " "
wget -nc --progress=dot $url 2>&1 | grep --line-buffered "%" | \
sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", )}'
echo -ne "\b\b\b\b"
echo " DONE"
}
```
file="adaway.org.txt"
echo -n "Downloading $file:"
download "https://raw.githubusercontent.com/EnergizedProtection/block/master/assets/active/filter/$file"
这仍然很粗糙,但可以工作。我只是想做一些变量来缩短底部,然后让我的 bash 从 cat 文件中读取。
您的问题不清楚,但听起来您可能正在尝试这样做:
$ cat a.txt
http://google.com/foo
http://yahoo.com/stuff/bar
$ cat tst.sh
#!/bin/env bash
input=""
while IFS= read -r line; do
path="${line%/*}"
file="${line##*/}"
printf '\nline="%s"\n' "$line"
printf 'path="%s"\n' "$path"
printf 'file="%s"\n' "$file"
echo download "${path}/${file}"
done < "$input"
$ ./tst.sh a.txt
line="http://google.com/foo"
path="http://google.com"
file="foo"
download http://google.com/foo
line="http://yahoo.com/stuff/bar"
path="http://yahoo.com/stuff"
file="bar"
download http://yahoo.com/stuff/bar
如果不是,请编辑您的问题以澄清。